feat: 算力引擎 Go 后端核心(new-api)
- 统一 OpenAI 兼容 /v1 中继 + 渠道/额度/令牌/流水 - 各领域包:relay 模型网关、model 数据层、controller 管理 API
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package tencent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
"github.com/QuantumNous/new-api/relay/channel/openai"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestDispatchAdaptorInit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
apiKey string
|
||||
baseURL string
|
||||
wantTC3 bool
|
||||
wantBaseURL string
|
||||
}{
|
||||
{
|
||||
name: "legacy three-segment key selects TC3 adaptor and keeps base url",
|
||||
apiKey: "1300000000|AKIDxxxxxxxx|secretxxxxxxxx",
|
||||
baseURL: constant.ChannelBaseURLs[constant.ChannelTypeTencent],
|
||||
wantTC3: true,
|
||||
wantBaseURL: constant.ChannelBaseURLs[constant.ChannelTypeTencent],
|
||||
},
|
||||
{
|
||||
name: "tokenhub key with default base url rewrites to tokenhub",
|
||||
apiKey: "sk-xxxxxxxxxxxxxxxx",
|
||||
baseURL: constant.ChannelBaseURLs[constant.ChannelTypeTencent],
|
||||
wantTC3: false,
|
||||
wantBaseURL: tokenHubBaseURL,
|
||||
},
|
||||
{
|
||||
name: "tokenhub key with empty base url rewrites to tokenhub",
|
||||
apiKey: "sk-xxxxxxxxxxxxxxxx",
|
||||
baseURL: "",
|
||||
wantTC3: false,
|
||||
wantBaseURL: tokenHubBaseURL,
|
||||
},
|
||||
{
|
||||
name: "tokenhub key with custom base url is preserved",
|
||||
apiKey: "sk-xxxxxxxxxxxxxxxx",
|
||||
baseURL: "https://proxy.example.com",
|
||||
wantTC3: false,
|
||||
wantBaseURL: "https://proxy.example.com",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
info := &relaycommon.RelayInfo{ChannelMeta: &relaycommon.ChannelMeta{
|
||||
ChannelType: constant.ChannelTypeTencent,
|
||||
ApiKey: tt.apiKey,
|
||||
ChannelBaseUrl: tt.baseURL,
|
||||
}}
|
||||
|
||||
dispatch := &DispatchAdaptor{}
|
||||
dispatch.Init(info)
|
||||
|
||||
require.NotNil(t, dispatch.Adaptor)
|
||||
if tt.wantTC3 {
|
||||
assert.IsType(t, &Adaptor{}, dispatch.Adaptor)
|
||||
} else {
|
||||
assert.IsType(t, &openai.Adaptor{}, dispatch.Adaptor)
|
||||
}
|
||||
assert.Equal(t, tt.wantBaseURL, info.ChannelBaseUrl)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user