-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support native json output and strict tool calls for anthropic #3457
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?
Conversation
| tools, strict_tools_requested = self._get_tools(model_request_parameters, model_settings) | ||
| tools, mcp_servers, beta_features = self._add_builtin_tools(tools, model_request_parameters) | ||
| output_format = self._build_output_format(model_request_parameters) | ||
| structured_output_beta_required = strict_tools_requested or bool(output_format) |
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.
We could simplify the code below by adding a value to the beta_headers list here right?
| 'input_schema': f.parameters_json_schema, | ||
| } | ||
| if f.strict is not None: | ||
| tool_param['strict'] = f.strict # type: ignore[assignment] |
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.
Look at how the OpenAI model uses is_strict_compatible. If the user didn't explicitly say strict=True on their tool, it'll be strict=None, so we check if the schema is strict-compatible, and if so we set strict=True.
So to get the same behavior with Anthropic, we should check if the schema can be transformed successfully (losslessly), and set strict=True unless it's explicitly strict=False
- Resolved conflicts in anthropic.py by keeping our strict tools and native JSON implementation - Resolved conflicts in test_anthropic.py by merging strict=True with TTL='5m' in assertions - Kept our test_anthropic_mixed_strict_tool_run test - Added upstream's new features: - count_tokens() method for token counting - TTL support for cache control (5m and 1h) - New helper methods (_infer_tool_choice, _map_extra_headers) - test_anthropic_cache_with_custom_ttl test
Fixes #3428
work in progress: