diff --git a/backend/internal/pkg/claude/sampling.go b/backend/internal/pkg/claude/sampling.go new file mode 100644 index 0000000000..a6016e7481 --- /dev/null +++ b/backend/internal/pkg/claude/sampling.go @@ -0,0 +1,21 @@ +package claude + +import "strings" + +var temperatureRejectingFamilies = []string{ + "claude-opus-4-7", + "claude-opus-4-8", +} + +func RejectsTemperature(model string) bool { + if IsOpus55(model) || IsFable52(model) || IsMythos52(model) { + return true + } + id := normalizeEffortModelID(model) + for _, family := range temperatureRejectingFamilies { + if id == family || strings.HasPrefix(id, family+"-") { + return true + } + } + return false +} diff --git a/backend/internal/pkg/claude/sampling_test.go b/backend/internal/pkg/claude/sampling_test.go new file mode 100644 index 0000000000..497d6d5dba --- /dev/null +++ b/backend/internal/pkg/claude/sampling_test.go @@ -0,0 +1,40 @@ +package claude + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestRejectsTemperature(t *testing.T) { + t.Parallel() + + tests := []struct { + model string + want bool + }{ + {model: "claude-opus-4-8", want: true}, + {model: "claude-opus-4-8-20260529", want: true}, + {model: "claude-opus-4-7", want: true}, + {model: "anthropic/claude-opus-4-8", want: true}, + {model: "us.anthropic.claude-opus-4-8-v1", want: true}, + {model: "claude-opus-5-5", want: true}, + {model: "anthropic/claude-opus-5.5", want: true}, + {model: "claude-fable-5-2", want: true}, + {model: "claude-mythos-5-2", want: true}, + {model: "claude-opus-4-6", want: false}, + {model: "claude-opus-4-5-20251101", want: false}, + {model: "claude-sonnet-4-6", want: false}, + {model: "claude-sonnet-5-5", want: false}, + {model: "claude-haiku-5-5", want: false}, + {model: "claude-haiku-4-5-20251001", want: false}, + {model: "gpt-5.6", want: false}, + {model: "", want: false}, + } + for _, tt := range tests { + t.Run(tt.model, func(t *testing.T) { + t.Parallel() + require.Equal(t, tt.want, RejectsTemperature(tt.model)) + }) + } +} diff --git a/backend/internal/service/account_test_service.go b/backend/internal/service/account_test_service.go index b195356fa9..61e12e2580 100644 --- a/backend/internal/service/account_test_service.go +++ b/backend/internal/service/account_test_service.go @@ -319,7 +319,7 @@ func createTestPayload(modelID string) (map[string]any, error) { return nil, err } - return map[string]any{ + payload := map[string]any{ "model": modelID, "messages": []map[string]any{ { @@ -347,10 +347,13 @@ func createTestPayload(modelID string) (map[string]any, error) { "metadata": map[string]string{ "user_id": sessionID, }, - "max_tokens": 1024, - "temperature": 1, - "stream": true, - }, nil + "max_tokens": 1024, + "stream": true, + } + if !claude.RejectsTemperature(modelID) { + payload["temperature"] = 1 + } + return payload, nil } // TestAccountConnection tests an account's connection by sending a test request @@ -693,6 +696,28 @@ func (s *AccountTestService) testClaudeVertexServiceAccountConnection(c *gin.Con return s.processClaudeStream(c, resp.Body) } +func buildBedrockTestPayload(modelID string) map[string]any { + payload := map[string]any{ + "anthropic_version": "bedrock-2023-05-31", + "messages": []map[string]any{ + { + "role": "user", + "content": []map[string]any{ + { + "type": "text", + "text": "hi", + }, + }, + }, + }, + "max_tokens": 256, + } + if !claude.RejectsTemperature(modelID) { + payload["temperature"] = 1 + } + return payload +} + // testBedrockAccountConnection tests a Bedrock (SigV4 or API Key) account using non-streaming invoke func (s *AccountTestService) testBedrockAccountConnection(c *gin.Context, ctx context.Context, account *Account, testModelID string) error { region := bedrockRuntimeRegion(account) @@ -710,23 +735,7 @@ func (s *AccountTestService) testBedrockAccountConnection(c *gin.Context, ctx co c.Writer.Flush() // Create a minimal Bedrock-compatible payload (no stream, no cache_control) - bedrockPayload := map[string]any{ - "anthropic_version": "bedrock-2023-05-31", - "messages": []map[string]any{ - { - "role": "user", - "content": []map[string]any{ - { - "type": "text", - "text": "hi", - }, - }, - }, - }, - "max_tokens": 256, - "temperature": 1, - } - bedrockBody, _ := json.Marshal(bedrockPayload) + bedrockBody, _ := json.Marshal(buildBedrockTestPayload(testModelID)) // Use non-streaming endpoint (response is standard Claude JSON) apiURL := BuildBedrockURL(region, testModelID, false) diff --git a/backend/internal/service/account_test_service_payload_test.go b/backend/internal/service/account_test_service_payload_test.go new file mode 100644 index 0000000000..865a9e4f01 --- /dev/null +++ b/backend/internal/service/account_test_service_payload_test.go @@ -0,0 +1,55 @@ +//go:build unit + +package service + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCreateTestPayload_Temperature(t *testing.T) { + tests := []struct { + model string + wantTemperature bool + }{ + {model: "claude-sonnet-4-6", wantTemperature: true}, + {model: "claude-opus-4-6", wantTemperature: true}, + {model: "claude-sonnet-5-5", wantTemperature: true}, + {model: "claude-haiku-5-5", wantTemperature: true}, + {model: "claude-opus-4-7", wantTemperature: false}, + {model: "claude-opus-4-8", wantTemperature: false}, + {model: "claude-opus-5-5", wantTemperature: false}, + {model: "claude-fable-5-2", wantTemperature: false}, + {model: "claude-mythos-5-2", wantTemperature: false}, + } + for _, tt := range tests { + t.Run(tt.model, func(t *testing.T) { + payload, err := createTestPayload(tt.model) + require.NoError(t, err) + + temperature, present := payload["temperature"] + require.Equal(t, tt.wantTemperature, present) + if tt.wantTemperature { + require.Equal(t, 1, temperature) + } + require.Equal(t, tt.model, payload["model"]) + }) + } +} + +func TestBuildBedrockTestPayload_Temperature(t *testing.T) { + tests := []struct { + model string + wantTemperature bool + }{ + {model: "us.anthropic.claude-sonnet-4-6", wantTemperature: true}, + {model: "us.anthropic.claude-opus-4-8-v1", wantTemperature: false}, + } + for _, tt := range tests { + t.Run(tt.model, func(t *testing.T) { + _, present := buildBedrockTestPayload(tt.model)["temperature"] + require.Equal(t, tt.wantTemperature, present) + }) + } +}