File size: 2,142 Bytes
955bb3b
 
f7c8859
955bb3b
f7c8859
46cc0db
955bb3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f1466c
 
 
3cd60cd
 
0f1466c
 
 
dc766b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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'
];