Skip to content
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

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

k11kirky
Copy link
Contributor

@k11kirky k11kirky commented Feb 4, 2025

ignore process cost in plugin server if input and output cost already set

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 add formatNumber 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

Comment on lines 29 to 30
completion_token: 0.000004,
},
Copy link
Contributor

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.

Comment on lines 102 to 103
const promptPrice = Number(model.pricing.prompt)
const completionPrice = Number(model.pricing.completion)
Copy link
Contributor

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.

Suggested change
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
}

Comment on lines 118 to 120
if (!fs.existsSync(baseDir)) {
fs.mkdirSync(baseDir)
}
Copy link
Contributor

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.

Suggested change
if (!fs.existsSync(baseDir)) {
fs.mkdirSync(baseDir)
}

Comment on lines 22 to 26
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']
}
Copy link
Contributor

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.

Comment on lines 103 to +105
const childrenMap = new Map<any, any[]>()
const idMap = new Map<any, LLMTraceEvent>()
const visitedNodes = new Set<any>()
Copy link
Contributor

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'.

@k11kirky k11kirky merged commit 6904c68 into master Feb 5, 2025
96 checks passed
@k11kirky k11kirky deleted the feat/allow-override-costs branch February 5, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants