mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-06 08:06:50 +00:00
fix(accounts): omit temperature from account tests for models that reject it
The Anthropic and Bedrock account test payloads always sent
temperature: 1, so testing claude-opus-4-8 failed with HTTP 400
("temperature is deprecated for this model") and a working account was
reported as broken.
Add claude.RejectsTemperature for Opus 4.7/4.8, Opus 5.5, Fable 5.2 and
Mythos 5.2, and skip the field for those models. Other models keep the
existing payload.
Fixes #8625
This commit is contained in:
1 parent
15871f9040
commit
75290a9f26
4 files changed
+147
-22
No files matched your search
@@ -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
|
||||
}
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user