mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-07-25 21:31:13 +02:00
Merge pull request #10 from praveentcom/cosine/optional-chaining-number-parsefloat
Use optional chaining for exactMatch check and Number.parseFloat in cost.ts
This commit is contained in:
@@ -166,7 +166,7 @@ export function getCostConfig(model: string): CostConfig {
|
|||||||
* Check Helicone costs with operator matching
|
* Check Helicone costs with operator matching
|
||||||
*/
|
*/
|
||||||
const exactMatch = heliconeCosts.get(normalizedModel);
|
const exactMatch = heliconeCosts.get(normalizedModel);
|
||||||
if (exactMatch && exactMatch.operator === "equals") {
|
if (exactMatch?.operator === "equals") {
|
||||||
return exactMatch.config;
|
return exactMatch.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,5 +229,5 @@ export function calculateCost(
|
|||||||
(completion_tokens / 1_000_000) * cost.output;
|
(completion_tokens / 1_000_000) * cost.output;
|
||||||
|
|
||||||
const total = inputCost + cachedCost + outputCost;
|
const total = inputCost + cachedCost + outputCost;
|
||||||
return total > 0 ? Number(total.toFixed(6)) : null;
|
return total > 0 ? Number.parseFloat(total.toFixed(6)) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,10 +97,10 @@ export async function GET(request: NextRequest) {
|
|||||||
summary: {
|
summary: {
|
||||||
totalRequests: Number.parseInt(summary.total_requests ?? '0'),
|
totalRequests: Number.parseInt(summary.total_requests ?? '0'),
|
||||||
totalTokens: Number.parseInt(summary.total_tokens_used ?? '0'),
|
totalTokens: Number.parseInt(summary.total_tokens_used ?? '0'),
|
||||||
totalCost: parseFloat(summary.total_cost ?? '0'),
|
totalCost: Number.parseFloat(summary.total_cost ?? '0'),
|
||||||
avgResponseTime: parseFloat(summary.avg_response_time ?? '0'),
|
avgResponseTime: Number.parseFloat(summary.avg_response_time ?? '0'),
|
||||||
uniqueModels: Number.parseInt(summary),
|
uniqueModels: Number.parseInt(summary.unique_models ?? '0'),
|
||||||
uniqueClients: parseInt(summary.unique_clients ?? '0'),
|
uniqueClients: Number.parseInt(summary.unique_clients ?? '0'),
|
||||||
},
|
},
|
||||||
recentRequests,
|
recentRequests,
|
||||||
modelBreakdown,
|
modelBreakdown,
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ export default function ModelBreakdown({ models }: ModelBreakdownProps) {
|
|||||||
</td>
|
</td>
|
||||||
<td style={styles.td}>{Number.parseInt(model.request_count).toLocaleString()}</td>
|
<td style={styles.td}>{Number.parseInt(model.request_count).toLocaleString()}</td>
|
||||||
<td style={styles.td}>{Number.parseInt(model.total_tokens).toLocaleString()}</td>
|
<td style={styles.td}>{Number.parseInt(model.total_tokens).toLocaleString()}</td>
|
||||||
<td style={styles.td}>${parseFloat(model.total_cost).toFixed(4)}</td>
|
<td style={styles.td}>${Number.parseFloat(model.total_cost).toFixed(4)}</td>
|
||||||
<td style={styles.td}>{Math.round(parseFloat(model.avg_response_time))}ms</td>
|
<td style={styles.td}>{Math.round(Number.parseFloat(model.avg_response_time))}ms</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default function RecentRequests({ requests }: RecentRequestsProps) {
|
|||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td style={styles.td}>${parseFloat(req.total_cost).toFixed(4)}</td>
|
<td style={styles.td}>${Number.parseFloat(req.total_cost).toFixed(4)}</td>
|
||||||
<td style={styles.td}>{req.response_time}ms</td>
|
<td style={styles.td}>{req.response_time}ms</td>
|
||||||
<td style={styles.td}>
|
<td style={styles.td}>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ export default function TrendsChart({ trends }: TrendsChartProps) {
|
|||||||
}),
|
}),
|
||||||
requests: Number.parseInt(trend.requests),
|
requests: Number.parseInt(trend.requests),
|
||||||
tokens: Number.parseInt(trend.tokens),
|
tokens: Number.parseInt(trend.tokens),
|
||||||
cost: parseFloat(trend.cost),
|
cost: Number.parseFloat(trend.cost),
|
||||||
responseTime: Math.round(parseFloat(trend.avg_response_time)),
|
responseTime: Math.round(Number.parseFloat(trend.avg_response_time)),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user