Repository navigation
Expand file tree
/
Copy pathllmProviderDefaults.ts
More file actions
63 lines (57 loc) · 2.24 KB
/
Copy pathllmProviderDefaults.ts
File metadata and controls
63 lines (57 loc) · 2.24 KB
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
62
63
/** Default models per provider — keep in sync with Python LLM clients. */
export const DEFAULT_LLM_MODEL_BY_PROVIDER: Record<string, string> = {
openai: 'gpt-4o-mini',
gemini: 'gemini-2.0-flash',
anthropic: 'claude-3-5-haiku-latest',
groq: 'openai/gpt-oss-120b',
ollama: 'llama3.2',
};
/** Common models offered in the chat composer for cloud providers. */
export const LLM_MODEL_PRESETS: Record<string, readonly string[]> = {
groq: [
'openai/gpt-oss-120b',
'llama-3.3-70b-versatile',
'llama-3.1-8b-instant',
],
openai: ['gpt-4o-mini', 'gpt-4o', 'gpt-4.1-mini'],
gemini: ['gemini-2.0-flash', 'gemini-2.5-flash-preview'],
anthropic: ['claude-3-5-haiku-latest', 'claude-3-5-sonnet-latest'],
};
export function defaultLlmModelForProvider(provider: string): string {
return DEFAULT_LLM_MODEL_BY_PROVIDER[provider] ?? '';
}
export function effectiveLlmModel(provider: string, model: string | undefined): string {
const trimmed = String(model ?? '').trim();
if (trimmed) return trimmed;
return defaultLlmModelForProvider(provider);
}
export function cloudModelPresets(provider: string): string[] {
const presets = LLM_MODEL_PRESETS[provider];
if (!presets?.length) return [];
const defaultModel = defaultLlmModelForProvider(provider);
const merged = defaultModel && !presets.includes(defaultModel)
? [defaultModel, ...presets]
: [...presets];
return [...new Set(merged)];
}
export function modelChipLabel(provider: string, model: string | undefined): string {
const effective = effectiveLlmModel(provider, model);
if (!effective) return '';
const slash = effective.lastIndexOf('/');
if (slash >= 0 && slash < effective.length - 1) {
return effective.slice(slash + 1);
}
return effective.length > 20 ? `${effective.slice(0, 19)}…` : effective;
}
/** Never persist an empty llm_model when a provider is selected. */
export function ensurePersistedLlmModel(entries: Record<string, string>): Record<string, string> {
const out = { ...entries };
const provider = String(out.llm_provider || 'none');
if (!String(out.llm_model || '').trim() && provider !== 'none') {
const defaultModel = defaultLlmModelForProvider(provider);
if (defaultModel) {
out.llm_model = defaultModel;
}
}
return out;
}