Spaces:
Running
Running
| import type { ChatModelProvider, TokenUsage } from './helpers/types'; | |
| export const MAX_MODELS_PER_NODE = 5; | |
| export const MAX_TRENDING_MODELS = 10; | |
| export const MAX_SUGGESTIONS = 2; | |
| export const MAX_DEFAULT_MODELS = 2; | |
| export function formatPricingCost(pricing: ChatModelProvider['pricing'], amount: number) { | |
| if (!pricing) return null; | |
| return `$${pricing.input * amount} for input, $${pricing.output * amount} for output`; | |
| } | |
| export function formatPricingPerToken(pricing: ChatModelProvider['pricing']) { | |
| if (!pricing) return null; | |
| const inPrice = pricing.input.toFixed(2); | |
| const outPrice = pricing.output.toFixed(2); | |
| return `In: $${inPrice}/1M • Out: $${outPrice}/1M`; | |
| } | |
| export function formatUsageCost(pricing: ChatModelProvider['pricing'], usage: TokenUsage) { | |
| if (!pricing || !usage) return null; | |
| const inputCost = (pricing.input / 1_000_000) * (usage.prompt_tokens ?? 0); | |
| const outputCost = (pricing.output / 1_000_000) * (usage.completion_tokens ?? 0); | |
| const total = inputCost + outputCost; | |
| if (total === 0) return null; | |
| return `$${total.toFixed(6)}`; | |
| } | |
| export function getProviderName(provider: string) { | |
| const providersMap = { | |
| together: 'togethercomputer' | |
| }; | |
| return providersMap[provider as keyof typeof providersMap] ?? provider; | |
| } | |