fix: include input_tokens in message_delta events for Anthropic compatibility#21
Open
dracpet wants to merge 1 commit intoAMAP-ML:mainfrom
Open
fix: include input_tokens in message_delta events for Anthropic compatibility#21dracpet wants to merge 1 commit intoAMAP-ML:mainfrom
dracpet wants to merge 1 commit intoAMAP-ML:mainfrom
Conversation
…tibility Some Anthropic-compatible clients (e.g., AgentScope/QwenPaw) expect input_tokens to be present in the message_delta event's usage object. Currently, stream_from_openai_result only includes output_tokens, which causes TypeError: '>' not supported between instances of 'NoneType' and 'int' in frameworks that parse usage.input_tokens from the final delta event. Solution: Add input_tokens to the usage dict in the message_delta event.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some Anthropic-compatible clients (e.g., AgentScope/QwenPaw) expect
input_tokensto be present in themessage_deltaevent's usage object. Currently,stream_from_openai_resultonly includesoutput_tokens, which causesTypeError: '>' not supported between instances of 'NoneType' and 'int'in frameworks that parseusage.input_tokensfrom the final delta event.Solution
Add
input_tokensto theusagedict in themessage_deltaevent, matching the value frommessage_start.Changed
Verification
Tested with:
All 10 test scenarios pass without regression.