{{ message }}
Repository navigation
fix(llm): send temperature through extra_body on anthropic>=1.0 - #2001
Open
abouchard11 wants to merge 1 commit into
Open
abouchard11 wants to merge 1 commit into
abouchard11 wants to merge 1 commit into
Conversation
anthropic 1.0.0 removed the temperature keyword from messages.create, so AnthropicClient raised "TypeError: AsyncMessages.create() got an unexpected keyword argument 'temperature'" on every call once a 1.x SDK was installed. pyproject allows it (anthropic>=0.49.0); uv.lock pins 0.111.0, so CI does not see it. The API still takes the field. When the installed SDK has no temperature keyword, pass it through extra_body, which the SDK merges into the request JSON. Older SDKs keep the keyword. The request body is the same in both cases.
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.

Summary
With
anthropic1.0.0 or later installed,AnthropicClientfails on every call:The 1.x SDK removed the
temperaturekeyword frommessages.create(), and_generate_responsealways passes it.pyproject.tomlallows 1.x (anthropic>=0.49.0) whileuv.lockpins 0.111.0, so CI does not see the failure but a freshpip install "graphiti-core[anthropic]"does.The API still accepts the field, and the SDK's v1 migration guide gives
extra_bodyas the way to send it. This change checks whether the installed SDK'smessages.createhas atemperaturekeyword:extra_body.The request body is the same in both cases, so
LLMConfig.temperaturekeeps working on either SDK line.Not changed here:
temperature=None(#1794, #1797) and which models accept sampling parameters. Both behave the same before and after this change.Type of change
rfc-approved)Related issue
Fixes #2000
Design approval
rfc-approvedlabel after discussion with the Graphiti team.Testing
make checkpasses.make formatandmake lintpass. I did not runmake testin full because it needs a local Neo4j; I ran the unit-test selection from.github/workflows/unit_tests.ymlinstead.Three tests added to
tests/llm_client/test_anthropic_client.py:temperaturekeyword receives the value throughextra_body.anthropicversion is installed. Onmainwith anthropic 1.13.0 this test fails with theTypeErrorabove.Results:
uv.lock)tests/llm_client/test_anthropic_client.pyunit_tests.ymlpyright ./graphiti_coreThe client tests also pass on anthropic 0.49.0 (the declared floor), 0.125.0 and 1.0.0.
I captured the HTTP request body with a local stub server. It is identical for
mainon 0.111.0, this branch on 0.111.0, and this branch on 1.13.0, withtemperaturepresent in all three.Breaking changes
Checklist
No documentation change: no public interface or documented behavior changes.