feat(opencode): add dynamic configuration and context discovery for LM Studio#15732
feat(opencode): add dynamic configuration and context discovery for LM Studio#15732TrentPierce wants to merge 4 commits intoanomalyco:devfrom
Conversation
|
Great, thank you! This feature is long overdue. Manually configuring local models and their capabilities, variants, etc is nuts. Automatic discovery is far better for most use cases. |
Thank you! I have developed a few tools for LMStudio, so I was surprised to see it not working well with OpenCode. This pull request was tested with the latest version of LMStudio. There are many more metrics we can discover automatically if needed in the future as well. |
|
Oh wow this is amazing |
Thank you! I'm looking forward to trying some of the new Qwen models in OpenCode. |
Issue for this PR
Closes #
#6231
#2456
#11141
#4232
Possibly many others related to LMStudio.
Type of change
What does this PR do?
This PR improves the LM Studio provider integration by allowing users to specify a custom server address and automatically discover their loaded model and context limits.
Configurable Base URL: Added a prompt during auth login to override the default LM Studio server address (e.g., for users running on different ports or remote machines).
Dynamic Context Discovery: The LMStudio loader now queries /v1/models to fetch the max_context_length and automatically configures model limits.
Improved Stability: Added an 8k token floor for context and a warning if a model is configured with less than 32k tokens (which can cause issues with OpenCode's system prompt).
How did you verify your code works?
Discovery: Ran opencode models --provider lmstudio --verbose and confirmed that max_context_length from LM Studio correctly populated the model's limit.context.
Connectivity: Verified that auth login correctly saves and uses a custom baseURL in auth.json.
Inference: Ran a test prompt using opencode run --model lmstudio/ to ensure the combined system prompt and user query fit within the dynamically discovered context window.
Checklist