Adding Support for local OpenAI-compatible APIs - #4
Open
jasonpaulso wants to merge 2 commits into
Open
jasonpaulso wants to merge 2 commits into
jasonpaulso wants to merge 2 commits into
Conversation
added 2 commits
July 11, 2025 14:12
- Add custom base URL support to OpenAI provider via OPENAI_BASE_URL env var - Add dedicated localopenai provider for better local API experience - Update documentation with local API setup instructions - Support popular local servers (LM Studio, Ollama, LocalAI, etc.) - Add .mcp-todos.json to gitignore
There was a problem hiding this comment.
Pull Request Overview
Adds support for local OpenAI-compatible APIs by extending the CLI’s LLM service and updating documentation.
- Introduce a new
localopenaiprovider inllm-service.tswith default endpoint and key fallback - Enhance the existing
openaiprovider to accept customOPENAI_BASE_URLenvironment variables - Extend
readme.mdwith detailed usage instructions and examples for local API servers
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/services/llm-service.ts | Added localopenai provider and updated openai to support custom base URLs |
| readme.md | Documented usage for local OpenAI-compatible APIs with examples |
Comments suppressed due to low confidence (1)
source/services/llm-service.ts:45
- New
localopenaiprovider logic has been added without accompanying tests; consider adding unit tests to verify factory behavior under various environment and configuration scenarios.
localopenai: {
| factory: (key: string, cfg: LLMConfig) => | ||
| new ChatOpenAI({openAIApiKey: key, modelName: cfg.model}), | ||
| factory: (key: string, cfg: LLMConfig) => { | ||
| const baseURL = process.env['OPENAI_BASE_URL'] || process.env['OPENAI_API_BASE']; |
There was a problem hiding this comment.
[nitpick] The base URL normalization logic is duplicated between the openai and localopenai providers; consider extracting this into a shared helper to reduce duplication and improve maintainability.
Comment on lines
+49
to
+51
| const baseURL = process.env['LOCAL_OPENAI_BASE_URL'] || 'http://localhost:1234/v1'; | ||
| const config: any = { | ||
| openAIApiKey: key || 'local-api-key', |
There was a problem hiding this comment.
[nitpick] Using a hardcoded fallback API key ('local-api-key') may lead to sending misleading credentials; consider allowing an empty key or requiring an explicit local key to avoid accidental misuse.
Suggested change
| const baseURL = process.env['LOCAL_OPENAI_BASE_URL'] || 'http://localhost:1234/v1'; | |
| const config: any = { | |
| openAIApiKey: key || 'local-api-key', | |
| if (!key) { | |
| throw new Error("API key for 'localopenai' provider must be explicitly provided."); | |
| } | |
| const baseURL = process.env['LOCAL_OPENAI_BASE_URL'] || 'http://localhost:1234/v1'; | |
| const config: any = { | |
| openAIApiKey: key, |
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.
This pull request introduces support for local OpenAI-compatible APIs, enabling users to integrate local models and servers into the CLI tool. The changes include updates to the documentation, new configuration options for local APIs, and enhancements to the LLM service to handle these providers.
Documentation Updates:
readme.md: Added instructions for using local OpenAI-compatible APIs, including configuration options for setting base URLs and API keys for local servers like LM Studio, Ollama, LocalAI, and Text Generation WebUI.readme.md: Updated the list of supported models to include thelocalopenaiprovider for local APIs.Code Enhancements:
source/services/llm-service.ts: Added a newlocalopenaiprovider to thePROVIDERSobject. This includes logic for handling local API endpoints, default models, and API keys, with fallback values for local use cases. Updated theopenaiprovider to support custom base URLs via environment variables.