(metric: MetricKey, value: number)
| 3 | import type { MetricKey } from './types'; |
| 4 | |
| 5 | export function formatMetric(metric: MetricKey, value: number): string { |
| 6 | switch (metric) { |
| 7 | case 'cost': |
| 8 | return formatDollars(fromMicrodollars(value)); |
| 9 | case 'requests': |
| 10 | return formatLargeNumber(value); |
| 11 | case 'tokens': |
| 12 | case 'inputTokens': |
| 13 | case 'outputTokens': |
| 14 | return formatLargeNumber(value); |
| 15 | case 'errorRate': |
| 16 | case 'cacheHitRatio': |
| 17 | return `${(value * 100).toFixed(1)}%`; |
| 18 | case 'avgLatencyMs': |
| 19 | case 'avgGenerationTimeMs': { |
| 20 | if (value >= 1000) { |
| 21 | return `${(value / 1000).toFixed(2)}s`; |
| 22 | } |
| 23 | return `${Math.round(value)}ms`; |
| 24 | } |
| 25 | case 'costPerRequest': |
| 26 | return formatMicrodollars(value, 4); |
| 27 | case 'tokensPerRequest': |
| 28 | return Math.round(value).toLocaleString(); |
| 29 | case 'outputInputRatio': |
| 30 | return `${value.toFixed(2)}x`; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | export function formatBytes(n: number): string { |
| 35 | return formatLargeNumber(n); |
no test coverage detected