Skip to content

Commit

Permalink
fix: usage display as NaN issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu-xiaowei committed Dec 15, 2024
1 parent 70972e4 commit 82eee89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
12 changes: 2 additions & 10 deletions react-native/src/settings/ModelPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,7 @@ export function getTotalCost(usage: Usage[]) {
}

export function getTotalInputTokens(usage: Usage[]) {
return Number(
usage
.reduce((sum, model) => sum + (model.inputTokens || 0), 0)
.toLocaleString()
);
return usage.reduce((sum, model) => sum + (model.inputTokens || 0), 0);
}

export function getTotalInputPrice(usage: Usage[]) {
Expand All @@ -310,11 +306,7 @@ export function getTotalInputPrice(usage: Usage[]) {
}

export function getTotalOutputTokens(usage: Usage[]) {
return Number(
usage
.reduce((sum, model) => sum + (model.outputTokens || 0), 0)
.toLocaleString()
);
return usage.reduce((sum, model) => sum + (model.outputTokens || 0), 0);
}

export function getTotalOutputPrice(usage: Usage[]) {
Expand Down
15 changes: 8 additions & 7 deletions react-native/src/settings/TokenUsageScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,32 @@ function TokenUsageScreen(): React.JSX.Element {
<View style={styles.totalHeader}>
<Text style={styles.totalLabel}>Total Usage</Text>
<Text style={styles.totalPrice}>
USD {getTotalCost(modelUsage)}
USD {getTotalCost(modelUsage).toString()}
</Text>
</View>
<View style={styles.totalRow}>
<Text style={styles.totalText}>
Input Tokens: {getTotalInputTokens(modelUsage)}
Input Tokens: {getTotalInputTokens(modelUsage).toLocaleString()}
</Text>
<Text style={styles.totalText}>
USD {getTotalInputPrice(modelUsage)}
USD {getTotalInputPrice(modelUsage).toString()}
</Text>
</View>
<View style={styles.totalRow}>
<Text style={styles.totalText}>
Output Tokens: {getTotalOutputTokens(modelUsage)}
Output Tokens:{' '}
{getTotalOutputTokens(modelUsage).toLocaleString()}
</Text>
<Text style={styles.totalText}>
USD {getTotalOutputPrice(modelUsage)}
USD {getTotalOutputPrice(modelUsage).toString()}
</Text>
</View>
<View style={styles.totalRow}>
<Text style={styles.totalText}>
Images: {getTotalImageCount(modelUsage)}
Images: {getTotalImageCount(modelUsage).toLocaleString()}
</Text>
<Text style={styles.totalText}>
USD {getTotalImagePrice(modelUsage)}
USD {getTotalImagePrice(modelUsage).toString()}
</Text>
</View>
</View>
Expand Down

0 comments on commit 82eee89

Please sign in to comment.