-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix Bedrock Converse streaming and token handling #1763
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
Fix Bedrock Converse streaming and token handling #1763
Conversation
|
|
||
| DefaultUsage usage = new DefaultUsage(promptTokens, generationTokens, totalTokens); | ||
|
|
||
| Document modelResponseFields = response.additionalModelResponseFields(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't seem to use modelResponseFields and metrics. Also, we don't copy all the metadata attributes into the ChatResponse here.
| && this.isToolCall(chatResponse, Set.of("tool_use"))) { | ||
| var toolCallConversation = this.handleToolCalls(prompt, chatResponse); | ||
| return this.call(new Prompt(toolCallConversation, prompt.getOptions())); | ||
| return this.internalCall(new Prompt(toolCallConversation, prompt.getOptions()), chatResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need test coverage to test this flow - especially to verify the final ChatResponse containing the preceding one.
| if (perviousChatResponse != null && perviousChatResponse.getMetadata() != null | ||
| && perviousChatResponse.getMetadata().getUsage() != null) { | ||
|
|
||
| promptTokens += perviousChatResponse.getMetadata().getUsage().getPromptTokens(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have manually verified this step. Is there an effective way we can add a test to validate this additive operation in our tests?
- Modify stream method to support recursive tool call handling - Update token tracking and metadata merging for streamed responses - Improve token usage calculation for tool use events - Update test cases to handle new response processing Resolves spring-projects#1743
- Modify call method to support recursive tool call handling - Add support for cumulative token tracking across tool call iterations - Introduce internal call method to track and aggregate token usage - Merge previous chat response tokens with current response tokens
65936a9 to
625a557
Compare
|
Thanks for updating the tests! LGTM, merging. |
|
Rebased, squashed, fixed check style error and merged as 00ede3f |
Resolves #1743