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

community: Add support for cross-region inference profile IDs in Bedrock Anthropic Claude token cost calculation #28167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lakinduboteju
Copy link

This change modifies the token cost calculation logic to support cross-region inference profile IDs for Anthropic Claude models. Instead of explicitly listing all regional variants of new inference profile IDs in the cost dictionaries, the code now extracts a base model ID from the input model ID (or inference profile ID), making it more maintainable and automatically supporting new regional variants.

These inference profile IDs follow the format: <region>.<vendor>.<model-name> (e.g., us.anthropic.claude-3-haiku-xxx, eu.anthropic.claude-3-sonnet-xxx).

Cross-region inference profiles are system-defined identifiers that enable distributing model inference requests across multiple AWS regions. They help manage unplanned traffic bursts and enhance resilience during peak demands without additional routing costs.

References for Amazon Bedrock's cross-region inference profiles:-

…ation

- Introduced support for cross-region (system-defined) inference profiles, enabling Amazon Bedrock to manage unplanned traffic bursts by leveraging compute resources across various AWS Regions.
- Updated the `_get_anthropic_claude_token_cost` function to accommodate cross-region inference profile IDs as model IDs.
- Implemented extraction of a 'base_model_id' by isolating the last two segments of the `model_id`, facilitating the mapping of cross-region inference profile IDs to their respective cost entries.
- Ensured that cross-region inference profiles, which maintain the same cost structure as their base models, are processed efficiently without the need to expand the cost dictionaries.
Copy link

vercel bot commented Nov 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Nov 17, 2024 7:32pm

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. community Related to langchain-community labels Nov 17, 2024
- Addressed linting errors by adjusting line lengths to comply with the maximum limit.
- This change ensures that the codebase remains clean and consistent with established formatting standards.
- Changed string literals in `bedrock_anthropic_callback.py` to use double quotes instead of single quotes.
- Ensures consistency and adherence to the preferred coding standards across the codebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

1 participant