fix: allow CUSTOM_MODEL to work without OPENAI_KEY for local endpoints#163
Open
octo-patch wants to merge 1 commit into
Open
fix: allow CUSTOM_MODEL to work without OPENAI_KEY for local endpoints#163octo-patch wants to merge 1 commit into
octo-patch wants to merge 1 commit into
Conversation
Local and OpenAI-compatible LLM endpoints (Ollama, LM Studio, etc.) do not require a real API key. Previously, setting CUSTOM_MODEL without OPENAI_KEY would leave the openai client as undefined, causing CUSTOM_MODEL to silently resolve to undefined and the app to throw "No model found". Fix providers.ts to create the openai client when CUSTOM_MODEL is set, using a placeholder API key so local endpoints are not blocked by key validation. Also correct the README which incorrectly referenced the non-existent OPENAI_MODEL variable instead of the actual CUSTOM_MODEL. Fixes dzhng#133, dzhng#98 Co-Authored-By: Octopus <liyuan851277048@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #133
Fixes #98
Problem
When users try to use a local or OpenAI-compatible LLM (Ollama, LM Studio, etc.) by setting
CUSTOM_MODELandOPENAI_ENDPOINTwithoutOPENAI_KEY, the app throws "No model found". This happens because:openaiclient is only created whenOPENAI_KEYis setcustomModeldepends on theopenaiclient:openai?.(process.env.CUSTOM_MODEL, ...)OPENAI_KEY,openaiisundefined, socustomModelis alsoundefinedgetModel()then throws "No model found" even thoughCUSTOM_MODELis setAdditionally, the README incorrectly references a non-existent
OPENAI_MODELenvironment variable (should beCUSTOM_MODEL), which has confused many users (#107, #98, #133).Solution
providers.ts: Create theopenaiclient when eitherOPENAI_KEYorCUSTOM_MODELis set. Local/compatible endpoints don't require a real API key, so we use'placeholder'as a fallback to satisfy the SDK's requirement.README.md: CorrectOPENAI_MODEL→CUSTOM_MODELand clarify thatOPENAI_KEYis not needed for local endpoints.Testing
Verified by tracing through the code: with
CUSTOM_MODEL=llama3.1andOPENAI_ENDPOINT=http://localhost:11434/v1(noOPENAI_KEY), theopenaiclient is now created andcustomModelis properly initialized.