fix(provider): normalize dotted anthropic model IDs
This commit is contained in:
parent
82c78e853b
commit
4f658f8e5e
4 changed files with 25 additions and 4 deletions
|
|
@ -162,7 +162,7 @@ func buildRequestBody(
|
||||||
}
|
}
|
||||||
|
|
||||||
result := map[string]any{
|
result := map[string]any{
|
||||||
"model": model,
|
"model": strings.ReplaceAll(model, ".", "-"),
|
||||||
"max_tokens": int64(maxTokens),
|
"max_tokens": int64(maxTokens),
|
||||||
"messages": []any{},
|
"messages": []any{},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,26 @@ func TestBuildRequestBody(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "normalizes dotted anthropic model ID",
|
||||||
|
messages: []Message{
|
||||||
|
{Role: "user", Content: "Hello"},
|
||||||
|
},
|
||||||
|
model: "claude-sonnet-4.6",
|
||||||
|
options: map[string]any{
|
||||||
|
"max_tokens": 8192,
|
||||||
|
},
|
||||||
|
want: map[string]any{
|
||||||
|
"model": "claude-sonnet-4-6",
|
||||||
|
"max_tokens": int64(8192),
|
||||||
|
"messages": []any{
|
||||||
|
map[string]any{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hello",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "missing max_tokens returns error",
|
name: "missing max_tokens returns error",
|
||||||
messages: []Message{
|
messages: []Message{
|
||||||
|
|
|
||||||
|
|
@ -218,6 +218,7 @@ func CreateProviderFromConfig(cfg *config.ModelConfig) (LLMProvider, string, err
|
||||||
if cfg.APIKey() == "" {
|
if cfg.APIKey() == "" {
|
||||||
return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model)
|
return nil, "", fmt.Errorf("api_key is required for anthropic protocol (model: %s)", cfg.Model)
|
||||||
}
|
}
|
||||||
|
modelID = strings.ReplaceAll(modelID, ".", "-")
|
||||||
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
|
return NewHTTPProviderWithMaxTokensFieldAndRequestTimeout(
|
||||||
cfg.APIKey(),
|
cfg.APIKey(),
|
||||||
apiBase,
|
apiBase,
|
||||||
|
|
|
||||||
|
|
@ -282,7 +282,7 @@ func TestGetDefaultAPIBase_Mimo(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateProviderFromConfig_Anthropic(t *testing.T) {
|
func TestCreateProviderFromConfig_AnthropicAPIKeyNormalizesDottedModelID(t *testing.T) {
|
||||||
cfg := &config.ModelConfig{
|
cfg := &config.ModelConfig{
|
||||||
ModelName: "test-anthropic",
|
ModelName: "test-anthropic",
|
||||||
Model: "anthropic/claude-sonnet-4.6",
|
Model: "anthropic/claude-sonnet-4.6",
|
||||||
|
|
@ -296,8 +296,8 @@ func TestCreateProviderFromConfig_Anthropic(t *testing.T) {
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
||||||
}
|
}
|
||||||
if modelID != "claude-sonnet-4.6" {
|
if modelID != "claude-sonnet-4-6" {
|
||||||
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4.6")
|
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4-6")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue