Using BedrockProxyChatModel with tools, the chatResponse.metadata.usage only contains the token usage of the last invocation to the model instead of the sum of all the invocations when tools were invoked
Comment From: tzolov
@DEG-7 can you please elaborate a bit?
Is this stream or non-stream request? What Bedrock model are you using? A sample to illustrate the problem would be appreciated.
Comment From: DEG-7
@tzolov Thanks you very much for the quick response. I'm using a stream request through a ChatClient (some defaultFunctions defined and withProxyToolCalls(false)) and BedrockProxyChatModel. chatClient.prompt() ... .call() .chatResponse()
For cases when the model is invoked more than 1 time because some tool/function execution is required, the BedrockProxyChatModel.toChatResponse use only the last model response to return the model token usage (the usages for previous invocations are not taken in consideration) DefaultUsage usage = new DefaultUsage(response.usage().inputTokens().longValue(), response.usage().outputTokens().longValue(), response.usage().totalTokens().longValue());
Let me know if now the issue is more clear. Thanks in advance.