全局统一映射

This commit is contained in:
CJACK
2026-04-26 01:58:15 +08:00
parent 1b0e8cbadb
commit f13ad231ac
36 changed files with 855 additions and 308 deletions

View File

@@ -6,7 +6,7 @@ import (
"ds2api/internal/prompt"
)
const ClaudeDefaultModel = "claude-sonnet-4-5"
const ClaudeDefaultModel = "claude-sonnet-4-6"
type Message struct {
Role string `json:"role"`

View File

@@ -104,6 +104,18 @@ func TestConvertClaudeToDeepSeek(t *testing.T) {
}
}
func TestConvertClaudeToDeepSeekUsesGlobalAliasResolution(t *testing.T) {
store := config.LoadStore()
req := map[string]any{
"model": "claude-3-5-sonnet-latest",
"messages": []any{map[string]any{"role": "user", "content": "Hi"}},
}
out := ConvertClaudeToDeepSeek(req, store)
if out["model"] != "deepseek-v4-flash" {
t.Fatalf("expected global alias resolution, got model=%q", out["model"])
}
}
func contains(s, sub string) bool {
return len(s) >= len(sub) && (s == sub || len(sub) == 0 || (len(s) > 0 && (indexOf(s, sub) >= 0)))
}

View File

@@ -348,8 +348,7 @@ func TestConvertClaudeToDeepSeekNoSystem(t *testing.T) {
}
}
func TestConvertClaudeToDeepSeekOpusUsesSlowMapping(t *testing.T) {
t.Setenv("DS2API_CONFIG_JSON", `{"keys":[],"accounts":[],"claude_mapping":{"fast":"deepseek-v4-flash","slow":"deepseek-v4-pro"}}`)
func TestConvertClaudeToDeepSeekOpusUsesGlobalAlias(t *testing.T) {
store := config.LoadStore()
req := map[string]any{
"model": "claude-opus-4-6",
@@ -357,6 +356,19 @@ func TestConvertClaudeToDeepSeekOpusUsesSlowMapping(t *testing.T) {
}
out := ConvertClaudeToDeepSeek(req, store)
if out["model"] != "deepseek-v4-pro" {
t.Fatalf("expected opus to use slow mapping, got %q", out["model"])
t.Fatalf("expected opus to use global alias, got %q", out["model"])
}
}
func TestConvertClaudeToDeepSeekUsesExplicitModelAlias(t *testing.T) {
t.Setenv("DS2API_CONFIG_JSON", `{"keys":[],"accounts":[],"model_aliases":{"claude-sonnet-4-6":"deepseek-v4-pro-search"}}`)
store := config.LoadStore()
req := map[string]any{
"model": "claude-sonnet-4-6",
"messages": []any{map[string]any{"role": "user", "content": "Hi"}},
}
out := ConvertClaudeToDeepSeek(req, store)
if out["model"] != "deepseek-v4-pro-search" {
t.Fatalf("expected explicit alias override, got %q", out["model"])
}
}