fix(models): stop sending temperature to Claude models that reject it (#4155)
Disable temperature and top_p for Claude models that reject non-default sampling values. Regenerate the model catalog and parity baseline, add request-body regression coverage, and clarify the documented sampling restrictions.main
parent
643f64180e
commit
5343ac47b7
|
|
@ -1033,6 +1033,8 @@
|
|||
"source": "https://docs.anthropic.com/en/docs/about-claude/models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -1065,6 +1067,8 @@
|
|||
"source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -1096,6 +1100,8 @@
|
|||
"source": "https://docs.anthropic.com/en/docs/about-claude/models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -1127,6 +1133,8 @@
|
|||
"source": "https://docs.anthropic.com/en/docs/about-claude/models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -1159,6 +1167,8 @@
|
|||
"source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -1190,6 +1200,8 @@
|
|||
"source": "https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting#supported-models",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
|
|||
|
|
@ -481,6 +481,8 @@
|
|||
"id": "claude-fable-5-1",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -498,6 +500,8 @@
|
|||
"id": "claude-opus-5",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -514,6 +518,8 @@
|
|||
"id": "claude-sonnet-5",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -530,6 +536,8 @@
|
|||
"id": "claude-fable-5",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -547,6 +555,8 @@
|
|||
"id": "claude-opus-4-8",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
@ -563,6 +573,8 @@
|
|||
"id": "claude-opus-4-7",
|
||||
"api": "anthropic-messages",
|
||||
"compat": {
|
||||
"supports_temperature": false,
|
||||
"supports_top_p": false,
|
||||
"thinking_mode": "adaptive",
|
||||
"supports_effort": true
|
||||
},
|
||||
|
|
|
|||
|
|
@ -56,20 +56,20 @@
|
|||
"aliyun/KnowledgeQA/qwq-plus": "7139911fda2d14b002889abbd06c185e550bec0984cea85116510b17ba4063ea",
|
||||
"aliyun/Rerank/gte-rerank-v2": "27219a2ffc212a35e9eeacf87da136410342e1915dd1141dc3357d7b40f9595b",
|
||||
"aliyun/Rerank/qwen3-rerank": "2b0b10a4c768fb157901e45586d0092e4ebe5ee5e92064a592aa726d8d133df2",
|
||||
"anthropic/KnowledgeQA/claude-fable-5": "8cb0c332960f271acac66df25e0b8a1259c863994b6d4ef3c9be3df47f85b5bc",
|
||||
"anthropic/KnowledgeQA/claude-fable-5-1": "fe4ee19f613745815e5caa1f258e67f9f9a901f5fc45c1d4cce030bfa6287b72",
|
||||
"anthropic/KnowledgeQA/claude-fable-5": "7de3476c027bee1ff6c57d80750c84cec1d405fafe746470e72d6d3f0d2c5142",
|
||||
"anthropic/KnowledgeQA/claude-fable-5-1": "a8fd85f4d84dc59d34f6088badbfaa149c025efaeb358bdf18b829a3759a84e3",
|
||||
"anthropic/KnowledgeQA/claude-haiku-4-5": "5eb4abef41f957d98c0a15c83de48c0e6b46be48d59f761ba6006c29010487f9",
|
||||
"anthropic/KnowledgeQA/claude-haiku-4-5-20251001": "50878a87d7d212c8f295f191343f77200d71e71337b934a07a949ce04ef976f1",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-5": "3536e5a1bb14f6e980eeda66cca9d7fc8bfea8c6b26937765069d93f713a673d",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-5-20251101": "78bfa567c9c17acb9488ea0a7aaccb5b0e73e840db8c4955731debf1382ff8cf",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-6": "96f08927c9e9df5c113102d498d38c1aab3a7280f350f14cfe8fad4dfcffe039",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-7": "7b85755f5c9166ecd8e2e25d1ac60e580aa982ec8ab735c52fdec20dd8fa0db0",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-8": "aedacfa002c376af796c1eae5063d9fb17a1b980e0528207621f47d723b702dd",
|
||||
"anthropic/KnowledgeQA/claude-opus-5": "6657decfbaaf44e3fc4aec8ac14fccd7e569e8614ce7127049a092de821132d3",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-7": "d5cac6382ff5bca2f303199ab6a9ccabf8c205569f6cd090ec64bbfd672b4ebe",
|
||||
"anthropic/KnowledgeQA/claude-opus-4-8": "7335b6d93baf2fc6a7776737df6bf58791e8aed08475017cbad66abcd48d573f",
|
||||
"anthropic/KnowledgeQA/claude-opus-5": "bb9cc2a045ce8d4ebd5ce65d61f8abf3f1bb19af817961eaea5faa802e0819e5",
|
||||
"anthropic/KnowledgeQA/claude-sonnet-4-5": "176ba6989053acf35be0a6acdd421c1c94c20f183358544eb0343c6e74897220",
|
||||
"anthropic/KnowledgeQA/claude-sonnet-4-5-20250929": "6757d77ed1d25cf80d04d2d35217a7f5d94e37f1b7c3545bf1613ac0494ec388",
|
||||
"anthropic/KnowledgeQA/claude-sonnet-4-6": "c00c494964632af431731f6fdf2ba4d697d42b8e58600e8a28e6a880ad6f0cda",
|
||||
"anthropic/KnowledgeQA/claude-sonnet-5": "bcb9eaafd30ca276f91fddf6bd62cdbdce38129300abd069e202245568273f41",
|
||||
"anthropic/KnowledgeQA/claude-sonnet-5": "57112aa6a5905f29ccb0030d75afa92defc8c40fe3c2923b7f6c75e73db1ccf5",
|
||||
"azure_openai/Embedding/text-embedding-3snapshot": "0c2f547ad2206affe719f6f0775ee73574a4dda8a7993a699ee9c4e7d4983cab",
|
||||
"azure_openai/KnowledgeQA/gpt-4.1snapshot": "6b6e303e1e4ed32f972e8224ab090f835e63570543036912809fc6e2551f923c",
|
||||
"azure_openai/KnowledgeQA/gpt-4osnapshot": "69fab35e2db1fab9640c72ab3b0c7acae322a1d0758c61ade28bc39fb9f9f750",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@
|
|||
// - Claude Opus 4.5 is the one extended-thinking-only model that also
|
||||
// accepts `output_config.effort`, so it carries supports_effort with
|
||||
// budget mode;
|
||||
// - temperature and top_p cannot be sent alongside thinking; prompt
|
||||
// - temperature and top_p cannot be sent alongside thinking, and Claude
|
||||
// Opus 4.7 and later (Opus 4.8, Opus 5, Fable 5 / 5.1) and Sonnet 5
|
||||
// reject non-default sampling values, so those entries carry
|
||||
// supports_temperature: false and supports_top_p: false and send no
|
||||
// sampling field at all
|
||||
// (https://platform.claude.com/docs/en/docs/about-claude/model-deprecations); prompt
|
||||
// caching uses `cache_control` breakpoints (including on tools), offers
|
||||
// a 1h TTL and reports cache usage;
|
||||
// - interleaved thinking still uses the `interleaved-thinking-2025-05-14`
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/Tencent/WeKnora/internal/models"
|
||||
"github.com/Tencent/WeKnora/internal/models/api"
|
||||
"github.com/Tencent/WeKnora/internal/models/api/anthropicmessages"
|
||||
"github.com/Tencent/WeKnora/internal/models/providers"
|
||||
modelruntime "github.com/Tencent/WeKnora/internal/models/runtime"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
|
|
@ -282,6 +283,11 @@ func TestOpenAIProtocolSelection(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// claudeNoSamplingModels reject non-default temperature/top_p/top_k values.
|
||||
var claudeNoSamplingModels = []string{
|
||||
"claude-opus-4-7", "claude-opus-4-8", "claude-opus-5", "claude-sonnet-5", "claude-fable-5", "claude-fable-5-1",
|
||||
}
|
||||
|
||||
func resolve(t *testing.T, provider, model string) *modelruntime.Resolved {
|
||||
t.Helper()
|
||||
r, err := modelruntime.Resolve(modelruntime.Ref{Provider: provider, Model: model})
|
||||
|
|
@ -304,6 +310,21 @@ func TestFamilyExpectations(t *testing.T) {
|
|||
if r := resolve(t, "azure_openai", "gpt-5.4-prod"); r.OpenAICompletions.SupportsTemperature {
|
||||
t.Error("azure gpt-5* deployment should not support temperature")
|
||||
}
|
||||
// Claude Opus 4.7 and later and Sonnet 5 reject non-default sampling
|
||||
// values, so the internal pipelines that set a fixed temperature must not
|
||||
// send temperature or top_p to these models.
|
||||
for _, model := range claudeNoSamplingModels {
|
||||
r := resolve(t, "anthropic", model)
|
||||
if r.AnthropicMessages.SupportsTemperature {
|
||||
t.Errorf("anthropic/%s should not support temperature", model)
|
||||
}
|
||||
if r.AnthropicMessages.SupportsTopP {
|
||||
t.Errorf("anthropic/%s should not support top_p", model)
|
||||
}
|
||||
}
|
||||
if r := resolve(t, "anthropic", "claude-sonnet-4-6"); !r.AnthropicMessages.SupportsTemperature {
|
||||
t.Error("anthropic/claude-sonnet-4-6 should still support temperature")
|
||||
}
|
||||
// A deployment named exactly gpt-5 / gpt-5-mini / gpt-5-nano must agree
|
||||
// with the openai vendor: the original GPT-5 trio rejects
|
||||
// reasoning_effort "none", so the picker must not offer thinking off.
|
||||
|
|
@ -554,3 +575,48 @@ func TestSignedRerankCredentialLabels(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestClaudeNoSamplingRequestBody builds the request body the way NewRemoteChat
|
||||
// does, from the resolved catalog entry. With thinking off, the anthropic
|
||||
// adapter sends top_p when temperature is not supported, so both flags have to
|
||||
// be off for these models to receive neither field.
|
||||
func TestClaudeNoSamplingRequestBody(t *testing.T) {
|
||||
build := func(t *testing.T, model string, effort api.ReasoningEffort) map[string]any {
|
||||
t.Helper()
|
||||
r := resolve(t, "anthropic", model)
|
||||
c := anthropicmessages.New(anthropicmessages.Config{
|
||||
Endpoint: api.Endpoint{Model: r.RemoteModel},
|
||||
Settings: r.AnthropicMessages,
|
||||
ThinkingLevels: r.ThinkingLevels,
|
||||
Reasoning: r.Spec.Reasoning,
|
||||
})
|
||||
body, err := c.BuildRequestBody(
|
||||
[]api.Message{{Role: "user", Content: "Hi"}},
|
||||
&api.Options{Temperature: 1, TopP: 0.9, ReasoningEffort: effort},
|
||||
false,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("build %s: %v", model, err)
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
for _, model := range claudeNoSamplingModels {
|
||||
efforts := []api.ReasoningEffort{""}
|
||||
if r := resolve(t, "anthropic", model); r.ThinkingLevels.Supports(api.ReasoningOff) {
|
||||
efforts = append(efforts, api.ReasoningOff)
|
||||
}
|
||||
for _, effort := range efforts {
|
||||
body := build(t, model, effort)
|
||||
for _, field := range []string{"temperature", "top_p", "top_k"} {
|
||||
if _, ok := body[field]; ok {
|
||||
t.Errorf("anthropic/%s (reasoning %q) sent %s", model, effort, field)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if body := build(t, "claude-sonnet-4-6", api.ReasoningOff); body["temperature"] != 1.0 {
|
||||
t.Errorf("anthropic/claude-sonnet-4-6 should still send temperature, got %v", body["temperature"])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue