mirror of
https://github.com/praveentcom/openproxy.git
synced 2026-02-12 14:02:46 +00: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:
4
cost.ts
4
cost.ts
@@ -166,7 +166,7 @@ export function getCostConfig(model: string): CostConfig {
|
||||
* Check Helicone costs with operator matching
|
||||
*/
|
||||
const exactMatch = heliconeCosts.get(normalizedModel);
|
||||
if (exactMatch && exactMatch.operator === "equals") {
|
||||
if (exactMatch?.operator === "equals") {
|
||||
return exactMatch.config;
|
||||
}
|
||||
|
||||
@@ -229,5 +229,5 @@ export function calculateCost(
|
||||
(completion_tokens / 1_000_000) * cost.output;
|
||||
|
||||
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: {
|
||||
totalRequests: Number.parseInt(summary.total_requests ?? '0'),
|
||||
totalTokens: Number.parseInt(summary.total_tokens_used ?? '0'),
|
||||
totalCost: parseFloat(summary.total_cost ?? '0'),
|
||||
avgResponseTime: parseFloat(summary.avg_response_time ?? '0'),
|
||||
uniqueModels: Number.parseInt(summary),
|
||||
uniqueClients: parseInt(summary.unique_clients ?? '0'),
|
||||
totalCost: Number.parseFloat(summary.total_cost ?? '0'),
|
||||
avgResponseTime: Number.parseFloat(summary.avg_response_time ?? '0'),
|
||||
uniqueModels: Number.parseInt(summary.unique_models ?? '0'),
|
||||
uniqueClients: Number.parseInt(summary.unique_clients ?? '0'),
|
||||
},
|
||||
recentRequests,
|
||||
modelBreakdown,
|
||||
|
||||
@@ -42,8 +42,8 @@ export default function ModelBreakdown({ models }: ModelBreakdownProps) {
|
||||
</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}>${parseFloat(model.total_cost).toFixed(4)}</td>
|
||||
<td style={styles.td}>{Math.round(parseFloat(model.avg_response_time))}ms</td>
|
||||
<td style={styles.td}>${Number.parseFloat(model.total_cost).toFixed(4)}</td>
|
||||
<td style={styles.td}>{Math.round(Number.parseFloat(model.avg_response_time))}ms</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
@@ -60,7 +60,7 @@ export default function RecentRequests({ requests }: RecentRequestsProps) {
|
||||
</small>
|
||||
</div>
|
||||
</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}>
|
||||
<span
|
||||
|
||||
@@ -41,8 +41,8 @@ export default function TrendsChart({ trends }: TrendsChartProps) {
|
||||
}),
|
||||
requests: Number.parseInt(trend.requests),
|
||||
tokens: Number.parseInt(trend.tokens),
|
||||
cost: parseFloat(trend.cost),
|
||||
responseTime: Math.round(parseFloat(trend.avg_response_time)),
|
||||
cost: Number.parseFloat(trend.cost),
|
||||
responseTime: Math.round(Number.parseFloat(trend.avg_response_time)),
|
||||
}));
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user