mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
Merge pull request #3737 from wucm667/fix/sync-models-non-v1-base-url
fix(models): 同步上游模型支持非 /v1 API 版本 base_url(如智谱 /v4)
This commit is contained in:
@@ -391,14 +391,7 @@ func buildV1ModelsURL(base string) string {
|
||||
}
|
||||
|
||||
func buildOpenAIModelsURL(base string) string {
|
||||
normalized := strings.TrimRight(strings.TrimSpace(base), "/")
|
||||
if strings.HasSuffix(normalized, "/v1/models") {
|
||||
return normalized
|
||||
}
|
||||
if strings.HasSuffix(normalized, "/v1") {
|
||||
return normalized + "/models"
|
||||
}
|
||||
return normalized + "/v1/models"
|
||||
return buildOpenAIEndpointURL(base, "/v1/models")
|
||||
}
|
||||
|
||||
func buildGeminiModelsURL(base string) string {
|
||||
|
||||
@@ -29,6 +29,61 @@ func TestBuildV1ModelsURL(t *testing.T) {
|
||||
require.Equal(t, "https://gateway.example.com/antigravity/v1/models", buildV1ModelsURL("https://gateway.example.com/antigravity/"))
|
||||
}
|
||||
|
||||
func TestBuildOpenAIModelsURL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
base string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "zhipu v4 coding base url",
|
||||
base: "https://open.bigmodel.cn/api/coding/paas/v4",
|
||||
want: "https://open.bigmodel.cn/api/coding/paas/v4/models",
|
||||
},
|
||||
{
|
||||
name: "openai v1 base url",
|
||||
base: "https://api.openai.com/v1",
|
||||
want: "https://api.openai.com/v1/models",
|
||||
},
|
||||
{
|
||||
name: "models url unchanged",
|
||||
base: "https://api.openai.com/v1/models",
|
||||
want: "https://api.openai.com/v1/models",
|
||||
},
|
||||
{
|
||||
name: "host fallback uses v1",
|
||||
base: "https://api.openai.com",
|
||||
want: "https://api.openai.com/v1/models",
|
||||
},
|
||||
{
|
||||
name: "trailing slash on v4",
|
||||
base: "https://open.bigmodel.cn/api/coding/paas/v4/",
|
||||
want: "https://open.bigmodel.cn/api/coding/paas/v4/models",
|
||||
},
|
||||
{
|
||||
name: "v2 base url",
|
||||
base: "https://gateway.example.com/openai/v2",
|
||||
want: "https://gateway.example.com/openai/v2/models",
|
||||
},
|
||||
{
|
||||
name: "v3 base url",
|
||||
base: "https://gateway.example.com/openai/v3",
|
||||
want: "https://gateway.example.com/openai/v3/models",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require.Equal(t, tt.want, buildOpenAIModelsURL(tt.base))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildGeminiModelsURL(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user