Fix missing tokens_used/cost_estimate tracking and force USD display on Cost Estimate#8
Fix missing tokens_used/cost_estimate tracking and force USD display on Cost Estimate#8AppurvaT27 wants to merge 3 commits into
Conversation
Signed-off-by: AppurvaT27 <appurva.talashilkar@ambibuzz.com>
Signed-off-by: AppurvaT27 <appurva.talashilkar@ambibuzz.com>
|
|
||
| DOCTYPE_NAME = "AI Agent Request" | ||
|
|
||
| def calculate_cost_estimate(provider: str, model: str, tokens: int) -> float: |
There was a problem hiding this comment.
provider is unused. The function accepts a provider argument but never uses it
| # Blended average rates per 1,000,000 tokens (assumes 3:1 input/output ratio) | ||
| rates = { | ||
| # OpenAI | ||
| "gpt-4o-mini": 0.25, |
There was a problem hiding this comment.
The code does exact matches on the model string and falls back to "gpt-4o-mini" for anything else. In practice model names can include versions/suffixes (e.g., "gpt-4o-mini-2025-05-01") so unknown models will silently get the fallback rate.
| "claude-3-5-haiku-20241022": 1.00, | ||
| } | ||
|
|
||
| rate = rates.get((model or "").strip(), rates.get("gpt-4o-mini")) |
There was a problem hiding this comment.
Case-sensitivity: keys are compared as-is. The good practice is to normalize to lowercase before matching.
| if not tokens: | ||
| return 0.0 | ||
|
|
||
| # Blended average rates per 1,000,000 tokens (assumes 3:1 input/output ratio) |
There was a problem hiding this comment.
The docstring/comment mentions "assumes 3:1 input/output ratio" but that assumption is not applied anywhere in the function (so it is confusing).
| } | ||
|
|
||
| rate = rates.get((model or "").strip(), rates.get("gpt-4o-mini")) | ||
| return float((tokens / 1_000_000.0) * rate) |
There was a problem hiding this comment.
I can see the function returns a float produced from arithmetic on floats. For monetary values you should prefer Decimal (or round to cents) to avoid representation/rounding issues when persisting/displaying.
| rates = { | ||
| # OpenAI | ||
| "gpt-4o-mini": 0.25, | ||
| "gpt-4o": 5.00, |
There was a problem hiding this comment.
Pricing accuracy: the per-model rates used appear hand-picked. Verify against the official provider pricing; otherwise you may misrepresent the cost.
…stead of using hardcoded rates Signed-off-by: AppurvaT27 <appurva.talashilkar@ambibuzz.com>
Description:
Fixes: #7
Problem:
Changes
1.executor.py
2.ai_agent_request.json
3.ai_agent_request.js