Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/accounts/classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
KindUnavailable = "unavailable"
KindInvalidRequest = "invalid_request"
KindModelNotAvailable = "model_not_available"
KindCanceled = "canceled"
)

const maxRetryAfter = 10 * time.Minute
Expand Down
23 changes: 22 additions & 1 deletion internal/accounts/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,29 @@ func CanonicalModelID(model string) string {
return key
}

// NormalizeModelName converts display-name formats sent by external clients
// into the canonical model ID used for routing. It currently strips a leading
// "Provider: " segment (single-word provider, no spaces) before lowercasing
// and folding separators so names like "DeepSeek: DeepSeek V4.1 Flash" become
// "deepseek-v4.1-flash".
func NormalizeModelName(model string) string {
model = strings.TrimSpace(model)
if model == "" {
return model
}
parts := strings.SplitN(model, ":", 2)
if len(parts) == 2 {
provider := strings.TrimSpace(parts[0])
displayName := strings.TrimSpace(parts[1])
if !strings.Contains(provider, " ") {
model = displayName
}
}
return CanonicalModelID(model)
}

func routeModel(model string) string {
id := CanonicalModelID(model)
id := NormalizeModelName(model)
if id == "" || id == "auto" {
return ""
}
Expand Down
14 changes: 14 additions & 0 deletions internal/accounts/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,17 @@ func TestQuotaCooledEmptyCatalogSurfacesQuotaHint(t *testing.T) {
t.Fatal("quota-cooled empty catalog must not count as a live candidate")
}
}

func TestNormalizeModelNameStripsProviderPrefix(t *testing.T) {
for input, want := range map[string]string{
"DeepSeek: DeepSeek V4.1 Flash": "deepseek-v4.1-flash",
"DeepSeek_V4.1_Flash": "deepseek-v4.1-flash",
"workbuddy/deepseek-v4.1-flash": "deepseek-v4.1-flash",
"MiniMax-M3": "minimax-m3",
"Qwen3.7-Plus": "qwen3.7-plus",
} {
if got := NormalizeModelName(input); got != want {
t.Fatalf("NormalizeModelName(%q) = %q, want %q", input, got, want)
}
}
}
2 changes: 1 addition & 1 deletion internal/api/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ func classifyAPIError(err error) accounts.Classified {
}
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return accounts.Classified{
Kind: accounts.KindUnavailable, Status: 499, Failover: false,
Kind: accounts.KindCanceled, Status: 499, Failover: false,
Code: "request_canceled", Message: err.Error(),
}
}
Expand Down
6 changes: 6 additions & 0 deletions internal/executor/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,12 @@ func (e ChatExecutor) classifyInProcessError(err error) accounts.Classified {
}
var providerErr *providers.Error
if !errors.As(err, &providerErr) || providerErr == nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return accounts.Classified{
Kind: accounts.KindCanceled, Status: 499, Failover: false,
Code: "request_canceled", Message: err.Error(),
}
}
return accounts.Classify(0, err.Error(), "", accounts.KindUnavailable, "")
}
message := strings.TrimSpace(providerErr.Message)
Expand Down
Loading