Repository navigation
fix(anthropic): stop sending temperature=0.7 by default - #870
Open
chengwudi1 wants to merge 1 commit into
Open
chengwudi1 wants to merge 1 commit into
chengwudi1 wants to merge 1 commit into
Conversation
LCAnthropicChat hardcoded temperature=0.7 and always put it on the wire. Current Claude models (Sonnet 5, Opus 4.7+) removed the sampling parameters outright and answer HTTP 400 for any of them, so the default configuration fails with "temperature is deprecated for this model" before the conversation starts. Reproduced offline by inspecting the outgoing payload: keys were [max_tokens, messages, model, temperature]. langchain_anthropic defaults temperature to None and strips None from the payload, so making None the default aligns the wrapper with its own library: models that removed the parameter no longer see it, and older models that accept it fall back to their server-side default. An explicitly passed temperature is still forwarded unchanged, and the other provider classes keep 0.7 because OpenAI-compatible endpoints accept it. This change is deliberately scoped to LCAnthropicChat.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #867
Problem
LCAnthropicChathardcodedtemperature=0.7and always put it on the wire. Current Claude models (Sonnet 5, Opus 4.7+, the Fable family) removed the sampling parameters entirely and reject any of them:So "Test connection" fails with the default config, before the conversation even starts — the request authenticates fine and dies on the body.
Root cause
libs/kotaemon/kotaemon/llms/chats/langchain_based.pypassedtemperature=0.7down unconditionally.langchain_anthropic's ownChatAnthropic.temperaturedefaults toNoneand stripsNonefrom the payload, so 0.7 was kotaemon's opinion on top of the library's own default.Change
LCAnthropicChatnow defaultstemperaturetoNone:temperature=0.3is still forwarded unchanged.Deliberately scoped to
LCAnthropicChatonly — the other provider classes keep 0.7, because OpenAI-compatible endpoints accept the parameter.Tests
Two payload-inspection tests added to
test_llms_chat_models.py, both offline (no API key, no network), mirroring the issue's reproduction:test_anthropic_chat_does_not_send_temperature_by_default— the payload must not containtemperature. Fails before this change (temperature: 0.7was present).test_anthropic_chat_forwards_explicit_temperature— an explicit value still reaches the provider.Verified payload before:
['max_tokens', 'messages', 'model', 'temperature']→ after:['max_tokens', 'messages', 'model'].Verification
Disclosure: an AI assistant was used to prepare this change; I reviewed the diff and ran the tests myself.