diff --git a/README.md b/README.md index 78d7dcaa..4dc4eb5c 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,10 @@ FIRECRAWL_KEY="your_firecrawl_key" OPENAI_KEY="your_openai_key" ``` -To use local LLM, comment out `OPENAI_KEY` and instead uncomment `OPENAI_ENDPOINT` and `OPENAI_MODEL`: +To use a local LLM, uncomment `OPENAI_ENDPOINT` and `CUSTOM_MODEL` (you do not need to set `OPENAI_KEY` when using a local endpoint): -- Set `OPENAI_ENDPOINT` to the address of your local server (eg."http://localhost:1234/v1") -- Set `OPENAI_MODEL` to the name of the model loaded in your local server. +- Set `OPENAI_ENDPOINT` to the address of your local server (eg."http://localhost:11434/v1") +- Set `CUSTOM_MODEL` to the name of the model loaded in your local server. ### Docker diff --git a/src/ai/providers.ts b/src/ai/providers.ts index ce305aa3..f4290aa3 100644 --- a/src/ai/providers.ts +++ b/src/ai/providers.ts @@ -10,12 +10,15 @@ import { getEncoding } from 'js-tiktoken'; import { RecursiveCharacterTextSplitter } from './text-splitter'; // Providers -const openai = process.env.OPENAI_KEY - ? createOpenAI({ - apiKey: process.env.OPENAI_KEY, - baseURL: process.env.OPENAI_ENDPOINT || 'https://api.openai.com/v1', - }) - : undefined; +// Create openai client when OPENAI_KEY is set, or when CUSTOM_MODEL is configured +// (local/OpenAI-compatible endpoints don't require a real API key) +const openai = + process.env.OPENAI_KEY || process.env.CUSTOM_MODEL + ? createOpenAI({ + apiKey: process.env.OPENAI_KEY || 'placeholder', + baseURL: process.env.OPENAI_ENDPOINT || 'https://api.openai.com/v1', + }) + : undefined; const fireworks = process.env.FIREWORKS_KEY ? createFireworks({