feat: 更新主流大模型供应商目录
- 按云服务、Coding Plan、API 网关和本地模型分组 - 新增兼容模型发现与供应商协议校验
This commit is contained in:
1 parent
01e4435f29
commit
d8b124fc7c
15 files changed
+838
-237
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"ezops/model"
|
||||
)
|
||||
|
||||
func TestResolveEndpoint(t *testing.T) {
|
||||
tests := []struct {
|
||||
provider string
|
||||
endpoint string
|
||||
want string
|
||||
}{
|
||||
{provider: "google", want: "https://generativelanguage.googleapis.com/v1beta/openai"},
|
||||
{provider: "openrouter", want: "https://openrouter.ai/api/v1"},
|
||||
{provider: "hunyuan", want: "https://tokenhub.tencentmaas.com/v1"},
|
||||
{provider: "mimo", want: "https://api.xiaomimimo.com/v1"},
|
||||
{provider: "together", want: "https://api.together.ai/v1"},
|
||||
{provider: "lmstudio", want: "http://localhost:1234/v1"},
|
||||
{provider: "new-api", want: ""},
|
||||
{provider: "new-api", endpoint: "https://llm.example.com/v1/", want: "https://llm.example.com/v1"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.provider+test.endpoint, func(t *testing.T) {
|
||||
if got := resolveEndpoint(test.provider, test.endpoint); got != test.want {
|
||||
t.Fatalf("resolveEndpoint() = %q, want %q", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveProtocol(t *testing.T) {
|
||||
for _, provider := range []string{"anthropic", "glm-coding", "minimax-coding"} {
|
||||
if got := resolveProtocol(provider); got != "anthropic" {
|
||||
t.Fatalf("resolveProtocol(%q) = %q, want anthropic", provider, got)
|
||||
}
|
||||
}
|
||||
for _, provider := range []string{"openai", "google", "openrouter", "new-api"} {
|
||||
if got := resolveProtocol(provider); got != "openai" {
|
||||
t.Fatalf("resolveProtocol(%q) = %q, want openai", provider, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderRequirements(t *testing.T) {
|
||||
if !isLocalLLMProvider("lmstudio") {
|
||||
t.Fatal("LM Studio should allow an empty API key")
|
||||
}
|
||||
if isLocalLLMProvider("new-api") {
|
||||
t.Fatal("New API should require an API key")
|
||||
}
|
||||
if !requiresExplicitEndpoint("new-api") || !requiresExplicitEndpoint("custom") {
|
||||
t.Fatal("API gateway providers should require an explicit endpoint")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanReuseMaskedAPIKey(t *testing.T) {
|
||||
saved := model.LLMConfig{ID: 1, Provider: "openai", Endpoint: "https://api.openai.com/v1"}
|
||||
if !canReuseMaskedAPIKey("openai", "https://api.openai.com/v1/", saved) {
|
||||
t.Fatal("same provider and endpoint should reuse the saved key")
|
||||
}
|
||||
if canReuseMaskedAPIKey("openai", "https://gateway.example.com/v1", saved) {
|
||||
t.Fatal("changed endpoint must not reuse the saved key")
|
||||
}
|
||||
if canReuseMaskedAPIKey("new-api", saved.Endpoint, saved) {
|
||||
t.Fatal("changed provider must not reuse the saved key")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user