Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
dist
.env
out
api.json
7 changes: 6 additions & 1 deletion autorouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ var knownProviderPrefixes = map[string]bool{
"perplexity": true,
"bedrock": true,
"azure": true,
"mistral": true,
}

func stripProviderPrefix(model string) (stripped string, hasPrefix bool) {
Expand All @@ -562,7 +563,11 @@ func stripProviderPrefix(model string) (stripped string, hasPrefix bool) {
}
prefix := model[:idx]
if knownProviderPrefixes[prefix] {
return model[idx+1:], true
stripped = model[idx+1:]
if strings.HasPrefix(stripped, prefix+"/") {
stripped = strings.TrimPrefix(stripped, prefix+"/")
}
return stripped, true
}
return model, false
}
2 changes: 2 additions & 0 deletions autorouter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,10 @@ func TestStripProviderPrefix(t *testing.T) {
{"fireworks prefix", "fireworks/accounts/fireworks/models/llama", "accounts/fireworks/models/llama", true},
{"xai prefix", "xai/grok-1", "grok-1", true},
{"perplexity prefix", "perplexity/sonar-small", "sonar-small", true},
{"repeated perplexity prefix", "perplexity/perplexity/sonar", "sonar", true},
{"bedrock prefix", "bedrock/anthropic.claude-3", "anthropic.claude-3", true},
{"azure prefix", "azure/gpt-4-deployment", "gpt-4-deployment", true},
{"mistral prefix", "mistral/codestral-2508", "codestral-2508", true},
{"multiple slashes preserved", "openai/gpt-4/turbo", "gpt-4/turbo", true},
{"empty string", "", "", false},
{"slash only - not a provider", "/", "/", false},
Expand Down
2 changes: 1 addition & 1 deletion detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func DetectProviderFromModel(model string) string {
if idx := strings.Index(model, "/"); idx >= 0 {
prefix := model[:idx]
switch prefix {
case "openai", "anthropic", "googleai", "groq", "fireworks", "xai", "perplexity", "bedrock", "azure":
case "openai", "anthropic", "googleai", "groq", "fireworks", "xai", "perplexity", "bedrock", "azure", "mistral":
return prefix
}
}
Expand Down
1 change: 1 addition & 0 deletions detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestDetectProviderFromModel(t *testing.T) {
{"perplexity/sonar prefix", "perplexity/sonar-small", "perplexity"},
{"bedrock/claude prefix", "bedrock/anthropic.claude-3", "bedrock"},
{"azure/gpt-4 prefix", "azure/gpt-4", "azure"},
{"mistral/codestral prefix", "mistral/codestral-2508", "mistral"},
{"unknown/ prefix returns unknown", "unknown/model", ""},
{"single slash only", "/", ""},
}
Expand Down
1 change: 1 addition & 0 deletions interceptors/billing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func TestDetectProvider(t *testing.T) {
{"gemini-1.5-flash", "googleai"},
{"llama-3-70b", "openai_compatible"},
{"mixtral-8x7b", "openai_compatible"},
{"mistral/codestral-2508", "mistral"},
{"unknown-model", ""},
}

Expand Down
Loading
Loading