Repository navigation
Conversation
max_tokens is a required parameter of the Anthropic Messages API, but the fallback in AnthropicModel._run/_arun was changed from 4096 to None. With the default AnthropicConfig (whose as_dict drops None values), model_config_dict is empty, so requests were sent with max_tokens=None, which the API rejects with a 400 invalid_request_error. Restore an integer fallback so AnthropicModel works out of the box.
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Related Issue
Closes #4370
Description
Summary
AnthropicModelsendsmax_tokens=Nonewhenever the user config omitsmax_tokens, so every call made with the defaultAnthropicConfigfails with a 400invalid_request_errorfrom the Anthropic API.Why (root cause)
PR #3874 changed the
max_tokensfallback inAnthropicModel._run/_arunfrom4096toNone(camel/models/anthropic_model.py:1156 and camel/models/anthropic_model.py:1301).max_tokensis a required parameter of the Anthropic Messages API: in the pinnedanthropic0.89.0 SDK,messages.create()declaresmax_tokens: intand enforces it with@required_args, and an explicitNoneis serialized into the request body as"max_tokens": nullrather than being omitted. With the defaultAnthropicConfig, whoseas_dict()dropsNonevalues (camel/configs/base_config.py:86),model_config_dictis{}, so theNonefallback always applies and every default-config request is rejected.The goal of #3874 — not capping responses when the user configures their own
max_tokens— is preserved: an explicitly configuredmax_tokensis still passed through unchanged. Only the unset case falls back to an integer again (4096, the value used before #3874 and valid for every Claude model).Changes
camel/models/anthropic_model.py: restore the integer fallback formax_tokensin_runand_arun.test/models/test_anthropic_model.py: addtest_run_default_config_sends_int_max_tokensandtest_arun_default_config_sends_int_max_tokens, which constructAnthropicModelwith the default config (emptymodel_config_dict) and mock clients, and assert the outgoing request carries anintmax_tokens.Testing (Python 3.12.14, anthropic 0.89.0, pytest 7.4.4)
New regression tests on the unpatched tree (fail as expected):
With the fix:
(The two ignored files fail collection in this environment for missing optional heavy dependencies
google-genai/torch; the 175 failures are pre-existing "Missing API key" errors unrelated to this change — the same run on the unpatched tree gives 177 failed / 382 passed, the difference being exactly the two new tests.)What is the purpose of this pull request?
Checklist
pyproject.tomland runuv lock(no dependency changes needed)