feat: 算力引擎 Go 后端核心(new-api)
- 统一 OpenAI 兼容 /v1 中继 + 渠道/额度/令牌/流水 - 各领域包:relay 模型网关、model 数据层、controller 管理 API
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package relay
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuildAlphaSearchRequestBodyPreservesUnknownFields(t *testing.T) {
|
||||
raw := []byte(`{
|
||||
"id":"req_1",
|
||||
"model":"gpt-5.1",
|
||||
"input":[{"role":"user","content":"hi"}],
|
||||
"commands":{"search_query":[{"q":"weather","recency":1}]},
|
||||
"settings":{"locale":"en"},
|
||||
"future_field":{"nested":true}
|
||||
}`)
|
||||
|
||||
out, err := buildAlphaSearchRequestBody(raw, "gpt-5.1", "gpt-5.1-mapped")
|
||||
require.NoError(t, err)
|
||||
|
||||
var body map[string]any
|
||||
require.NoError(t, common.Unmarshal(out, &body))
|
||||
assert.Equal(t, "gpt-5.1-mapped", body["model"])
|
||||
assert.Equal(t, "req_1", body["id"])
|
||||
require.Contains(t, body, "commands")
|
||||
require.Contains(t, body, "settings")
|
||||
require.Contains(t, body, "future_field")
|
||||
require.Contains(t, body, "input")
|
||||
|
||||
commands, ok := body["commands"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
require.Contains(t, commands, "search_query")
|
||||
|
||||
future, ok := body["future_field"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, true, future["nested"])
|
||||
}
|
||||
|
||||
func TestBuildAlphaSearchRequestBodyNoMappingKeepsRawBytes(t *testing.T) {
|
||||
raw := []byte(`{"model":"gpt-5.1","commands":{"search_query":[{"q":"x"}]},"future_field":1}`)
|
||||
out, err := buildAlphaSearchRequestBody(raw, "gpt-5.1", "gpt-5.1")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, raw, out)
|
||||
}
|
||||
Reference in New Issue
Block a user