feat(opencode): dynamic model discovery for local providers (LM Studio, llama.cpp, etc.)#17670
feat(opencode): dynamic model discovery for local providers (LM Studio, llama.cpp, etc.)#17670dmitryryabkov wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs Found
The current PR (#17670) explicitly acknowledges PRs #15732 and #13234 as prior attempts but argues that this implementation is more robust because it's provider-agnostic, maintains backward compatibility, and works with any OpenAI-compatible provider supporting the |
Issue for this PR
Closes #6231
Type of change
What does this PR do?
Adds an option for dynamic model list population for OpenAI-compatible providers supporting
/modelAPI (as opposed to manually typing them inopencode.json):"provider"inopencode.json:"dynamicModelList": truetrueissues an API request and retrieves the list of the models supported by the provider"dynamicModelList": trueflag is setThis change makes working with local AI inference engines much nicer, because it eliminates the need to update
opencode.jsonevery time a new model is added, or if the engine is started with the specific model as a parameter. The model list is now completely driven by the inference engine itself.Example configuration (
opencode.json):{ "$schema": "https://opencode.ai/config.json", "provider": { "llama.cpp": { "npm": "@ai-sdk/openai-compatible", "name": "llama.cpp (local)", "options": { "baseURL": "http://127.0.0.1:8080/v1" }, "dynamicModelList": true }, "lm_studio": { "npm": "@ai-sdk/openai-compatible", "name": "LM Studio (local)", "options": { "baseURL": "http://127.0.0.1:1234/v1", }, "dynamicModelList": true } } }will result in the following model list in OpenCode, for LM Studio with "Just-in-Time Model Loading" enabled:
or llama.cpp started without specifying a model:
The selected model will be loaded by the inference engine once the first
/chat/completionrequest is received.If, however, the inference engines only serving specific models, only those models will be returned and available in OpenCode model selector. For LM Studio with "Just-in-Time Model Loading" disabled:
or llama.cpp started with a specific model:
I'm aware that there's a number of opened PRs on this issue already (i.e. #15732, #13234), however I believe this is the most robust implementation because:
/modelendpoint (not even just a local one, i.e. Ollama Cloud also works just fine)🤖 Developed with some help from OpenCode running against a local model hosted in llama.cpp!
How did you verify your code works?
Run OpenCode with models hosted in LM Studio and llama.cpp. Tried various scenarios:
Also tested it agains Ollama Cloud
Screenshots / recordings
See above
Checklist