community[minor]: add bedrock anthropic callback for token usage counting (#19864)

**Description:** add bedrock anthropic callback for token usage
counting, consulted openai callback.

---------

Co-authored-by: Massimiliano Pronesti <massimiliano.pronesti@gmail.com>
This commit is contained in:
Shuqian
2024-04-09 22:18:48 +08:00
committed by GitHub
parent 1f9f4d8742
commit ad9750403b
5 changed files with 202 additions and 2 deletions

View File

@@ -308,7 +308,7 @@ class BedrockChat(BaseChatModel, BedrockBase):
final_output = {}
for output in llm_outputs:
output = output or {}
usage = output.pop("usage", {})
usage = output.get("usage", {})
for token_type, token_count in usage.items():
final_usage[token_type] += token_count
final_output.update(output)