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]: Handle non text llm tokens #6179

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

bracesproul
Copy link
Collaborator

@bracesproul bracesproul commented Jul 23, 2024

Closes #6045

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 7:04pm
langchainjs-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2024 7:04pm

@snlamm
Copy link
Contributor

snlamm commented Jul 23, 2024

@bracesproul I think instead/in addition we need handle type: 'input_json_delta'?

Here's a snippet of the chunks that are generated when I run a prompt using tools - the actual text is in the input_json_delta:

[
  {
    index: 0,
    type: 'tool_use',
    id: 'toolu_01DfwKsAZ97rf3zLJmVd6cyU',
    name: 'extract',
    input: ''
  }
]
[ { index: 0, input: '', type: 'input_json_delta' } ]
[ { index: 0, input: '{"choi', type: 'input_json_delta' } ]
[ { index: 0, input: 'ces": [{"', type: 'input_json_delta' } ]
[ { index: 0, input: 'type": ', type: 'input_json_delta' } ]
[ { index: 0, input: '"knowle', type: 'input_json_delta' } ]
[ { index: 0, input: 'dge', type: 'input_json_delta' } ]
[ { index: 0, input: 'Overview", ', type: 'input_json_delta' } ]
[ { index: 0, input: '"description', type: 'input_json_delta' } ]
[ { index: 0, input: '": "', type: 'input_json_delta' } ]
[ { index: 0, input: 'Identify', type: 'input_json_delta' } ]
...

@bracesproul
Copy link
Collaborator Author

@bracesproul I think instead/in addition we need handle type: 'input_json_delta'?

Here's a snippet of the chunks that are generated when I run a prompt using tools - the actual text is in the input_json_delta:

[
  {
    index: 0,
    type: 'tool_use',
    id: 'toolu_01DfwKsAZ97rf3zLJmVd6cyU',
    name: 'extract',
    input: ''
  }
]
[ { index: 0, input: '', type: 'input_json_delta' } ]
[ { index: 0, input: '{"choi', type: 'input_json_delta' } ]
[ { index: 0, input: 'ces": [{"', type: 'input_json_delta' } ]
[ { index: 0, input: 'type": ', type: 'input_json_delta' } ]
[ { index: 0, input: '"knowle', type: 'input_json_delta' } ]
[ { index: 0, input: 'dge', type: 'input_json_delta' } ]
[ { index: 0, input: 'Overview", ', type: 'input_json_delta' } ]
[ { index: 0, input: '"description', type: 'input_json_delta' } ]
[ { index: 0, input: '": "', type: 'input_json_delta' } ]
[ { index: 0, input: 'Identify', type: 'input_json_delta' } ]
...

Updated to just check if input exists.

@bracesproul bracesproul marked this pull request as ready for review July 23, 2024 18:48
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs labels Jul 23, 2024
@bracesproul bracesproul merged commit e576ade into main Jul 23, 2024
38 checks passed
@bracesproul bracesproul deleted the brace/anthropic-non-txt-tokens branch July 23, 2024 19:17
@snlamm
Copy link
Contributor

snlamm commented Jul 23, 2024

@bracesproul after trying it out, it looks like the current implementation accidentally breaks on the first message_start event. I've opened a PR to fix here if that's helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs size:S This PR changes 10-29 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