-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: main
Are you sure you want to change the base?
Conversation
from langchain_core.callbacks import BaseCallbackHandler | ||
from langchain_core.outputs import LLMResult | ||
|
||
MODEL_COST_PER_1K_INPUT_TOKENS = { |
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.
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] + ( |
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.
For Anthropic and Nova models, tokens for cache reads and writes have a different pricing
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 created a new PR that adds callback support to ChatBedrockConverse: #324
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.
@grvvrmtech, thank you for the submission. However, at this time, we are looking to avoid maintaining the hard-coded lists of models and prices on the front-end.
Adding callback function for token usage counting, consulted openai callback.
Co-authored-by: Gaurav Verma [email protected]