Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/search/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ const vercel: EmbeddingProvider = {
}),
};

function applyEnvOverrides(provider: EmbeddingProvider): EmbeddingProvider {
const baseUrl = process.env.LAT_LLM_BASE_URL;
const model = process.env.LAT_LLM_MODEL;
if (!baseUrl && !model) return provider;
return {
...provider,
...(baseUrl ? { apiBase: baseUrl } : {}),
...(model ? { model } : {}),
};
}

export function detectProvider(key: string): EmbeddingProvider {
if (key.startsWith('REPLAY_LAT_LLM_KEY::')) {
const replayUrl = key.slice('REPLAY_LAT_LLM_KEY::'.length);
Expand All @@ -44,9 +55,19 @@ export function detectProvider(key: string): EmbeddingProvider {
"Anthropic doesn't offer an embedding model. Set LAT_LLM_KEY to an OpenAI (sk-...) or Vercel AI Gateway (vck_...) key.",
);
}
if (key.startsWith('vck_')) return vercel;
if (key.startsWith('sk-')) return openai;
if (key.startsWith('vck_')) return applyEnvOverrides(vercel);
if (key.startsWith('sk-')) return applyEnvOverrides(openai);
// Ollama and other local OpenAI-compatible providers (no auth required)
if (key === 'ollama' || key === 'local') {
return {
name: 'ollama',
apiBase: process.env.LAT_LLM_BASE_URL ?? 'http://localhost:11434/v1',
model: process.env.LAT_LLM_MODEL ?? 'nomic-embed-text',
dimensions: 768,
headers: () => ({ 'Content-Type': 'application/json' }),
};
}
throw new Error(
`Unrecognized LAT_LLM_KEY prefix. Supported: OpenAI (sk-...), Vercel AI Gateway (vck_...).`,
`Unrecognized LAT_LLM_KEY prefix. Supported: OpenAI (sk-...), Vercel AI Gateway (vck_...), Ollama (ollama).`,
);
}