Skip to content

community: have ChatLlamaCpp handle "auto" and "any" for tool_choice #30810

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

Closed
wants to merge 4 commits into from

Conversation

clinty
Copy link

@clinty clinty commented Apr 13, 2025

Description: This adds "auto" and "any" to ChatLlamaCpp's tool_choice options, and handles them both by selecting the first tool in the list
Issue: trustcall assumes support for "any" at https://github.com/AIXerum/trustcall/blob/main/trustcall/_base.py#L717

Copy link

vercel bot commented Apr 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 25, 2025 7:09pm

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. community Related to langchain-community labels Apr 13, 2025
@@ -362,6 +363,8 @@ def bind_tools(
f"Tool choice {tool_choice=} was specified, but the only "
f"provided tools were {tool_names}."
)
elif isinstance(tool_choice, str) and tool_choice in ['any', 'auto']:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't "auto" and "any" have different meanings? Doesn't "auto" typically mean the model can elect not to call a tool? See for example OpenAI and Anthropic docs.

@@ -362,6 +363,8 @@ def bind_tools(
f"Tool choice {tool_choice=} was specified, but the only "
f"provided tools were {tool_names}."
)
elif isinstance(tool_choice, str) and tool_choice in ['any', 'auto']:
tool_choice = formatted_tools[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if tools is length one, then we should translate "any" as you do here, but if there are multiple tools, we should raise an error.

@ccurme ccurme self-assigned this Apr 13, 2025
@clinty clinty force-pushed the llamacpp-auto-any branch from 2adf9ab to 2df023f Compare April 14, 2025 01:12
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 14, 2025
@clinty
Copy link
Author

clinty commented Apr 14, 2025

@ccurme what about this? I suppose it does the wrong thing if there's a tool called "auto".

Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "auto" should have the same behavior as None for tool choice, right? Should we just assign None in that case?

For "any", my thought is to do something like this:

if tool_choice == "any":
    if len(formatted_tools) == 1:
        tool_choice = formatted_tools[0]
    else:
        raise ValueError(
            "tool_choice `'any'` only supported if one tool is provided."
        )

This change will need some tests as well.

@clinty clinty force-pushed the llamacpp-auto-any branch from 2df023f to 58fd626 Compare April 14, 2025 16:57
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 14, 2025
@clinty
Copy link
Author

clinty commented Apr 14, 2025

@ccurme where should the tests go?

Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, can you add a test here?

Copy link
Collaborator

@ccurme ccurme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clinty we've now moved langchain-community into a standalone repo. Would you mind opening your PR there with a test? Feel free to tag me.

https://github.com/langchain-ai/langchain-community

@ccurme ccurme closed this Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants