Spaces:
Sleeping
Sleeping
| 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', | |
| sambanova: 'sambanovasystems' | |
| }; | |
| return providersMap[provider as keyof typeof providersMap] ?? provider; | |
| } | |
| export function getInitials(name: string): string { | |
| return name | |
| .split(' ') | |
| .slice(0, 2) | |
| .map((w) => w[0]?.toUpperCase() ?? '') | |
| .join(''); | |
| } | |
| export function getAvatarClass(name: string): string { | |
| let hash = 0; | |
| for (let i = 0; i < name.length; i++) { | |
| hash = name.charCodeAt(i) + ((hash << 5) - hash); | |
| } | |
| return AVATAR_CLASSES[Math.abs(hash) % AVATAR_CLASSES.length]; | |
| } | |
| export const AVATAR_CLASSES = [ | |
| 'bg-rose-100 text-rose-700 dark:bg-rose-900/30 dark:text-rose-300', | |
| 'bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300', | |
| 'bg-teal-100 text-teal-700 dark:bg-teal-900/30 dark:text-teal-300', | |
| 'bg-sky-100 text-sky-700 dark:bg-sky-900/30 dark:text-sky-300', | |
| 'bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-300', | |
| 'bg-slate-100 text-slate-600 dark:bg-slate-700/50 dark:text-slate-300' | |
| ]; | |