instructor-ai / instructor

structured outputs for llms
https://python.useinstructor.com/
MIT License
8.37k stars 662 forks source link

Anthropic `tool_choice` should be `any` #1085

Open josepablog opened 1 month ago

josepablog commented 1 month ago

What Model are you using?

Describe the bug

Doesn't seem the tools are being sent to (Bedrock) Anthropic correctly. For instance, if I set set_verbose=True on the README example, I can see that tool_choice is not being sent:

{'model': 
     'claude-3-opus-20240229',
      'messages': [{'role': 'user', 'content': [{'type': 'text', 'text': 'Extract Jason is 25 years old.'}]}],
       'max_tokens': 1024,
       'tools': [{'name': 'User', 'description': 'Correctly extracted `User` with all the required parameters with correct types', 'input_schema': {'properties': {'name': {'title': 'Name', 'type': 'string'}, 'age': {'title': 'Age', 'type': 'integer'}}, 'required': ['age', 'name'], 'type': 'object'}}]}'

Per Anthropic's [documentation](https://docs.anthropic.com/en/docs/build-with-claude/tool-use] the default is:

auto: allows Claude to decide whether to call any provided tools or not. This is the default value.

Without this, in more complicated examples, Claude is not obliged to generate a valid JSON.

jxnl commented 1 month ago

would love a pr to fix this

josepablog commented 1 month ago

Would you mind pointing me to some files? I can certainly try if I get a chance

On Thu, Oct 17, 2024 at 6:29 PM Jason Liu @.***> wrote:

would love a pr to fix this

— Reply to this email directly, view it on GitHub https://github.com/instructor-ai/instructor/issues/1085#issuecomment-2421039076, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN7KAI4L23K7XKAQBZJN3TZ4BP7LAVCNFSM6AAAAABQC3MZ32VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRRGAZTSMBXGY . You are receiving this because you authored the thread.Message ID: @.***>