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

adding bedrock token usage callback handler #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

grvvrmtech
Copy link

Adding callback function for token usage counting, consulted openai callback.

Co-authored-by: Gaurav Verma [email protected]

from langchain_core.callbacks import BaseCallbackHandler
from langchain_core.outputs import LLMResult

MODEL_COST_PER_1K_INPUT_TOKENS = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of models should be updated.

  • Pricing for meta has changed
  • New Anthropic models
  • New Nova models

f"Unknown model: {model_id}. Please provide a valid Bedrock model name."
"Known models are: " + ", ".join(MODEL_COST_PER_1K_INPUT_TOKENS.keys())
)
return (prompt_tokens / 1000) * MODEL_COST_PER_1K_INPUT_TOKENS[model_id] + (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Anthropic and Nova models, tokens for cache reads and writes have a different pricing

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new PR that adds callback support to ChatBedrockConverse: #324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants