-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Handle errors in cost calculation in InstrumentedModel #2834
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
Conversation
"opentelemetry-api>=1.28.0", | ||
"typing-inspection>=0.4.0", | ||
"genai-prices>=0.0.22", | ||
"genai-prices>=0.0.23", |
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.
There was a significant fix in price calculation logic released here, so I think this needs to be the minimum.
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.
Pull Request Overview
This PR improves error handling in the cost calculation within InstrumentedModel to prevent instrumentation failures. The change ensures that any unexpected errors during cost calculation result in a warning rather than crashing the instrumentation.
- Added comprehensive exception handling for cost calculation errors
- Updated the genai-prices dependency to version 0.0.23
- Added test coverage for cost calculation error scenarios
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
pydantic_ai_slim/pydantic_ai/models/instrumented.py | Added exception handling for cost calculation and CostCalculationFailedWarning class |
tests/models/test_instrumented.py | Added test case to verify warning behavior when cost calculation fails |
pydantic_ai_slim/pyproject.toml | Updated genai-prices dependency version to 0.0.23 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Docs Preview
|
|
||
import pytest | ||
from inline_snapshot import snapshot | ||
from inline_snapshot.extra import warns |
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.
cute.
A user reported an error being thrown by
.cost()
: https://pydanticlogfire.slack.com/archives/C083V7PMHHA/p1757110611141589I can't repro this, but in general instrumentation shouldn't cause errors.