-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Anthropic extended thinking with tool use and minor fixes #2487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,12 +247,29 @@ async def _messages_create( | |
tools = self._get_tools(model_request_parameters) | ||
tools += self._get_builtin_tools(model_request_parameters) | ||
tool_choice: BetaToolChoiceParam | None | ||
thinking = model_settings.get('anthropic_thinking', NOT_GIVEN) | ||
temperature = model_settings.get('temperature', NOT_GIVEN) | ||
top_p = model_settings.get('top_p', NOT_GIVEN) | ||
|
||
if not tools: | ||
tool_choice = None | ||
else: | ||
if not model_request_parameters.allow_text_output: | ||
tool_choice = {'type': 'any'} | ||
if thinking and thinking.get('type') == 'enabled': | ||
tool_choice = {'type': 'auto'} | ||
if temperature and temperature != 1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather have the user see an error and adjust this manually, than to change it for them and log warnings. So please remove this from the PR for now and keep it focused on the tool choice issue. If others report the temperature/top_p issue and find it hard to work around, we can consider something like this then. |
||
warnings.warn( | ||
'Anthropic only allows temperature set to 1 or not given, if thinking enabled using 1 for now', | ||
UserWarning, | ||
) | ||
temperature = 1 | ||
if top_p and top_p < 0.95: | ||
warnings.warn( | ||
'Anthropic only allows top_p greater than or equal to 0.95 or not given, if thinking enabled using 0.95 for now', | ||
UserWarning, | ||
) | ||
top_p = 0.95 | ||
else: | ||
tool_choice = {'type': 'auto'} | ||
|
||
|
@@ -273,10 +290,10 @@ async def _messages_create( | |
tools=tools or NOT_GIVEN, | ||
tool_choice=tool_choice or NOT_GIVEN, | ||
stream=stream, | ||
thinking=model_settings.get('anthropic_thinking', NOT_GIVEN), | ||
thinking=thinking, | ||
stop_sequences=model_settings.get('stop_sequences', NOT_GIVEN), | ||
temperature=model_settings.get('temperature', NOT_GIVEN), | ||
top_p=model_settings.get('top_p', NOT_GIVEN), | ||
temperature=temperature, | ||
top_p=top_p, | ||
timeout=model_settings.get('timeout', NOT_GIVEN), | ||
metadata=model_settings.get('anthropic_metadata', NOT_GIVEN), | ||
extra_headers=extra_headers, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert these change that seem specific to your environment