Skip to content
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

core, anthropic[patch]: support streaming tool calls when function has no arguments #23915

Merged
merged 6 commits into from
Jul 5, 2024

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Jul 5, 2024

resolves #23911

When an AIMessageChunk is instantiated, we attempt to parse tool calls off of the tool_call_chunks.

Here we add a special-case to this parsing, where "" will be parsed as {}.

This is a reaction to how Anthropic streams tool calls in the case where a function has no arguments:

{'id': 'toolu_01J8CgKcuUVrMqfTQWPYh64r', 'input': {}, 'name': 'magic_function', 'type': 'tool_use', 'index': 1}
{'partial_json': '', 'type': 'tool_use', 'index': 1}

The partial_json does not accumulate to a valid json string-- most other providers tend to emit "{}" in this case.

Copy link

vercel bot commented Jul 5, 2024

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 Jul 5, 2024 6:48pm

@ccurme ccurme changed the title anthropic[patch]: support streaming tool calls when function has no arguments core, anthropic[patch]: support streaming tool calls when function has no arguments Jul 5, 2024
@ccurme ccurme marked this pull request as ready for review July 5, 2024 16:53
@ccurme
Copy link
Collaborator Author

ccurme commented Jul 5, 2024

Integration tests passing for partner packages: https://github.com/langchain-ai/langchain/actions/runs/9811346308

Copy link
Member

@efriis efriis left a comment

Choose a reason for hiding this comment

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

small nit otherwise lgtm

libs/core/langchain_core/messages/ai.py Outdated Show resolved Hide resolved
@efriis efriis added the partner label Jul 5, 2024
@efriis efriis self-assigned this Jul 5, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases labels Jul 5, 2024
@ccurme ccurme enabled auto-merge (squash) July 5, 2024 18:54
@ccurme ccurme merged commit 74c7198 into master Jul 5, 2024
258 checks passed
@ccurme ccurme deleted the cc/tool_calls_no_args branch July 5, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases partner size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: anthropic streaming tool calls for tools with no arguments
2 participants