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

anthropic[patch]: ensure content exists when parsing tool tokens #6183

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

snlamm
Copy link
Contributor

@snlamm snlamm commented Jul 23, 2024

Fixes #6045

When anthropic extracts tokens during tool use, it's throwing an error on the message_start event, as it results in a chunk with an empty content array, but the current token parsing assumes that a single content item always exists. This PR fixes the issue.

{
  type: 'message_start',
  message: {
    id: 'msg123',
    type: 'message',
    role: 'assistant',
    model: 'claude-3-5-sonnet-20240620',
    content: [],
    stop_reason: null,
    stop_sequence: null,
    usage: { input_tokens: 1486, output_tokens: 12 }
  }
}

The current error thrown:

error: TypeError: Cannot use 'in' operator to search for 'input' in undefined
        at extractToken

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 23, 2024
Copy link

vercel bot commented Jul 23, 2024

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

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2024 8:40pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2024 8:40pm

@snlamm
Copy link
Contributor Author

snlamm commented Jul 23, 2024

cc @bracesproul

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 23, 2024
Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

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

Thanks for pushing up this fix. I pushed a commit adding a test as well.

@snlamm
Copy link
Contributor Author

snlamm commented Jul 23, 2024

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature lgtm PRs that are ready to be merged as-is size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChatAnthropic streaming with tools not working and instead forces non-stream response
2 participants