Skip to content

fix(evaluations): use correct total_cost property in CostCalculator#6183

Merged
HenryHengZJ merged 2 commits into
FlowiseAI:mainfrom
aviu16:fix/cost-calculator-total-price-typo
Apr 10, 2026
Merged

fix(evaluations): use correct total_cost property in CostCalculator#6183
HenryHengZJ merged 2 commits into
FlowiseAI:mainfrom
aviu16:fix/cost-calculator-total-price-typo

Conversation

@aviu16

@aviu16 aviu16 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

What happened

CostCalculator.ts line 28 checks costValues.total_price, but every other part of the codebase (models.json, evaluation runners) uses total_cost. Since total_price is always undefined, the condition is never true and models that define a flat total_cost rate fall through to the input_cost/output_cost path — which are also undefined for those models, producing NaN costs.

Fix

Change total_pricetotal_cost on line 28 to match the actual property name.

The condition on line 28 checked costValues.total_price, but the
property is total_cost everywhere else (models.json, evaluation
runners, etc.). Since total_price is always undefined, the branch
never executed and models that only define a flat total_cost rate
fell through to the input_cost/output_cost path, producing NaN.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request corrects a property name mismatch in the cost calculation logic by changing total_price to total_cost. The feedback suggests using a nullish check for both total_cost and totalTokens to properly handle free models and prevent potential NaN results.

}

if (costValues.total_price > 0) {
if (costValues.total_cost > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The fix correctly addresses the property name mismatch. However, using > 0 will cause models with a zero cost (free models) to fall through to the else block, which may still result in NaN if input_cost or output_cost are missing. Additionally, checking for the existence of totalTokens prevents NaN results if that metric is missing. Using a nullish check (!= null) is consistent with the project's standard idiom for covering both null and undefined.

Suggested change
if (costValues.total_cost > 0) {
if (costValues.total_cost != null && totalTokens != null) {
References
  1. In JavaScript/TypeScript, use loose equality (== null) as a standard idiom for a 'nullish' check that covers both null and undefined.

@HenryHengZJ

Copy link
Copy Markdown
Contributor

thank you!

@HenryHengZJ HenryHengZJ merged commit 92f0797 into FlowiseAI:main Apr 10, 2026
3 checks passed
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