Add support for custom providers and local models#52
Conversation
|
@dundalek is attempting to deploy a commit to the Yury Selivanov's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
I would prefer the custom |
| } catch { | ||
| return null; | ||
| } | ||
| if (!key) return null; |
There was a problem hiding this comment.
Why remove this check? Can it not simply stay as is?
There was a problem hiding this comment.
This is to allow connecting to local llama-server without authentication.
|
|
||
| export function detectProvider(key: string): EmbeddingProvider { | ||
| if (key.startsWith('REPLAY_LAT_LLM_KEY::')) { | ||
| function customProvider(config: LatConfig): EmbeddingProvider | null { |
There was a problem hiding this comment.
Maybe check more carefully. Number() can produce NaN for invalid strings. Suggested code below.
function customProvider(config: LatConfig): EmbeddingProvider | null {
const base = process.env.LAT_LLM_BASE ?? config.llm_base;
if (!base) return null;
return {
name: 'custom',
apiBase: base,
model: process.env.LAT_LLM_MODEL ?? config.llm_model ?? 'default',
dimensions: (() => {
const envDimensions = process.env.LAT_LLM_DIMENSIONS;
if (envDimensions != null) {
const parsed = parseInt(envDimensions, 10);
if (isNaN(parsed)) throw new Error(`Invalid LAT_LLM_DIMENSIONS: "${envDimensions}"`);
return parsed;
}
return config.llm_dimensions ?? 1536;
})(),
headers: (k) => {
const h: Record<string, string> = {
'Content-Type': 'application/json',
};
if (k) h['Authorization'] = `Bearer ${k}`;
return h;
},
};
}
There was a problem hiding this comment.
good point, probably want to extract it as variable instead of IIFE
|
As a note since creating the PR I discovered draft of llm uri scheme spec. That would make setting it more convenient, instead of needing 4 env vars like: We could use a single var like:
But I will wait on maintainer feedback before spending more time on this. |
Resolves #8
Alternative implementation to #36
By providing options to specify custom endpoint, we can cover both uses of using local models and using different providers. See updated README.md for details.
AI disclamer: Claude Code used