Repository navigation
Cover cache-aware effective cost with unit tests and fix Anthropic cache-read field - #32
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
devin-ai-integration[bot] wants to merge 2 commits into
devin-ai-integration[bot] wants to merge 2 commits into
Conversation
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_effective_costhad no test asserting its output: the mocked cost tests hard-codecached_tokens = 0and only assert token totals, so the cache-read/cache-write arithmetic was multiplied by zero in every non-pricytest. This adds unit tests that assert exact effective-cost floats for both providers with non-zero cache tokens, and fixes the bug the tests immediately exposed.Bug: the Anthropic branch read cache-read tokens from a field the Anthropic API does not emit, so all cache-read cost was silently dropped:
The old name is kept as a fallback so any caller/response still using it keeps working.
New tests in
tests/llm/test_tracking.pydrive a tiny_CostModel(TrackAPIPricingMixin)with fixedinput_cost/output_cost(no provider, no pricing fetch) and cover:cache_read_input_tokens+cache_creation_input_tokens, and without cache tokensprompt_tokens_details) with cached tokens and withprompt_tokens_details = Noneinput_tokens_details) with cached tokensusage is None→0.0, unsupported provider →0.0, litellm →completion_cost__call__accumulatingstats["effective_cost"]across two callsPlain
MagicMockcannot be used for the OpenAI dispatch (hasattr(usage, "prompt_tokens_details")is always true on a mock), hence the small_FakeUsagehelper, which also supportsdict(usage)asTrackAPIPricingMixin.__call__requires.Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/25cba9f25dfd4bd6985865c065a92a08
Open in Devin Desktop: https://app.devin.ai/desktop/session/25cba9f25dfd4bd6985865c065a92a08?variant=devin