fix(batch): count CostTracker requests even without litellm#5
Merged
Conversation
record() and record_from_usage() early-returned when LITELLM_AVAILABLE was false, so with litellm uninstalled (the CI environment) nothing was ever recorded and summary()['per_model'] came back empty - KeyError in callers and 3 failing tests. now the request count and per-model entry are always tracked; only the cost figure depends on litellm (stays 0.0 without it).
codex reviewCodex review is not configured for this repository yet. Missing required secret: |
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.
why
CI is red on main.
tests/test_batch.py::TestCostTrackerhas 3 failing tests (KeyError: 'test-model'), and they fail on a clean checkout too - this is pre-existing, not caused by any recent change.root cause:
CostTracker.record()andrecord_from_usage()both early-returnwhenLITELLM_AVAILABLEis false. litellm is an optional dependency and isn't installed in the CI test environment, so every call was a no-op,self.costsstayed empty, andsummary()["per_model"]came back with no keys. callers that index by model name thenKeyError.fix
always create the per-model entry and increment the request count; gate only the cost computation on litellm (cost stays
0.0when it's absent). request counting is the part that should never depend on an optional pricing library.verification
TestCostTrackertests passtest_api_launcher.py, which needscachetoolsnot installed in my local env; it passes in CI)