-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: force decimal notiation for large floats #28252
Conversation
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.
PR Summary
This PR standardizes floating-point number representation across AI cost configuration files, changing from scientific notation to decimal notation, while also adding logic to skip cost processing when values are pre-set.
- Modified
update-ai-costs.ts
to addformatNumber
function ensuring consistent decimal notation output (e.g., 0.0000008 instead of 8e-7) - Updated
processAiEvent.ts
to skip cost calculations when input/output costs are already set - Added circular reference detection in
llmObservabilityTraceDataLogic.ts
to prevent infinite loops during trace tree restoration - Added new model variants with costs across providers (e.g., 'llama-3.1-8b-instruct:nitro', 'deepseek-r1-distill-llama-70b:free')
- Adjusted some model costs, particularly for o1-mini models in OpenAI configuration with reduced token costs
11 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile
completion_token: 0.000004, | ||
}, |
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.
style: Consider using TypeScript const assertions (as const) on the costs array to ensure type safety of the model names and prevent accidental modifications.
const promptPrice = Number(model.pricing.prompt) | ||
const completionPrice = Number(model.pricing.completion) |
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.
logic: Missing validation for NaN values after Number conversion. Could silently pass through invalid pricing data.
const promptPrice = Number(model.pricing.prompt) | |
const completionPrice = Number(model.pricing.completion) | |
const promptPrice = Number(model.pricing.prompt) | |
const completionPrice = Number(model.pricing.completion) | |
if (isNaN(promptPrice) || isNaN(completionPrice)) { | |
console.warn('Skipping model with invalid pricing:', model) | |
continue | |
} |
if (!fs.existsSync(baseDir)) { | ||
fs.mkdirSync(baseDir) | ||
} |
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.
logic: Redundant directory existence check and creation. This was already done on line 80-83.
if (!fs.existsSync(baseDir)) { | |
fs.mkdirSync(baseDir) | |
} |
if (event.properties['$ai_input_cost_usd'] || event.properties['$ai_output_cost_usd']) { | ||
if (!event.properties['$ai_total_cost_usd']) { | ||
event.properties['$ai_total_cost_usd'] = | ||
event.properties['$ai_input_cost_usd'] + event.properties['$ai_output_cost_usd'] | ||
} |
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.
logic: This check allows either input OR output cost to trigger the skip logic. Could lead to incomplete cost calculations if only one is set.
const childrenMap = new Map<any, any[]>() | ||
const idMap = new Map<any, LLMTraceEvent>() | ||
const visitedNodes = new Set<any>() |
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.
style: Using 'any' type for Map and Set keys could lead to unexpected behavior. Consider using more specific types like 'string | number'.
ignore process cost in plugin server if input and output cost already set