GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(opencode): add auto model detection for OpenAI-compatible providers by tomzhu1024 · Pull Request #8359 · anomalyco/opencode Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs FoundBased on the search results, there are two PRs that appear to be related to or potentially addressing similar functionality:
Recommendation: You should review these PRs to check if they have been merged, closed, or superseded, and whether PR #8359 builds upon or duplicates their work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I was going to add this this week, some notes:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I wanted to add this as well! LMStudio does have api to fetch each model info with context length etc |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
It's not like "completely dropped" it should be like any model that exists in models.dev that isnt in models endpoint should be dropped but that doesnt mean drop all the useful metadata it's more to filter potentially unsupported models |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Then we should defo use that, wanna do the same for ollama but that can be separate |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rekram1-node I would love to help out on this if possible |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yeah up to yall I'd really like to ship this week so @tomzhu1024 if you aren't going to be available I think @goniz or myself will take care of this. Ig we can build off this PR easily |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Got it. This is definitely the optimal way. Thanks for the clarification! I was planning to iterate this PR later today -- I'm planning to 1) remove the extra config option, 2) still honor the model info from Models.dev (if they do exist according to the endpoint), 3) leave some space for provider-specific model info retrieval (like @goniz mentioned). I'm a little unsure about expanding this feature to all But feel free to take it over; just let me know so I can shift to something else. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
All the providers should work, I can test and iterate to make sure it works but ik u would use your github token from oauth exchange for copilot, and an api key for zen, etc so i think most things will be pretty standard. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I see. That sounds good. I'll then try to 4) expand it to all |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I've got initial draft for probing loaded models for LMStudio and Ollama. I'm using the OllamaLMStudioThe output is raw atm but I'll fix it tomorrow then I'll push something |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
23396df to
5080e14
Compare
There was an error while loading. Please reload this page.
|
I just got a chance to work on it. Now:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
5080e14 to
875c8bc
Compare
| @@ -943,6 +944,15 @@ export namespace Provider { | |||
| log.info("found", { providerID }) | |||
| } | |||
|
|
|||
| // auto-detect models | |||
| for (const [providerID, provider] of Object.entries(providers)) { | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We need to make this somewhat optimal so make sure:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Promise.all.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done. I moved this slightly in provider.ts so custom providers like "ollama" aren’t skipped just because they don’t exist in Models.dev, and the model.api.npm patch for @ai-sdk/github-copilot no longer has to run twice.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
awesome, ill take a look
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've pushed my PR with the ollama+lmstudio apis. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
/review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const providerNPM = configProvider?.npm ?? modelsDevProvider?.npm ?? "@ai-sdk/openai-compatible" | ||
| const providerBaseURL = configProvider?.options?.baseURL ?? configProvider?.api ?? modelsDevProvider?.api | ||
|
|
||
| let detectedModels: Record<string, Partial<Provider.Model>> | undefined = undefined |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Style suggestion: Consider refactoring to avoid the let statement. You could use an early return pattern or the Result pattern. For example:
if (providerNPM !== "@ai-sdk/openai-compatible" || !providerBaseURL) return const detectedModels = await ProviderModelDetection.OpenAICompatible.listModels(providerBaseURL, provider)
This eliminates the need for let and the subsequent if (detectedModels === undefined) return check becomes unnecessary.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is mainly for future extensibility, like we may have model detection for non-@ai-sdk/openai-compatible providers, or we may have a different detection method for a specific @ai-sdk/compatible provider (e.g. LMStudio/Ollama).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| type OpenAICompatibleResponse = z.infer<typeof OpenAICompatibleResponse> | ||
|
|
||
| export async function listModels(baseURL: string, provider: Provider.Info): Promise<Record<string, Partial<Provider.Model>>> { | ||
| let res: Response |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Style suggestion: These let statements combined with multiple try/catch blocks could potentially be refactored. The style guide advises avoiding let and try/catch where possible.
One option is to let exceptions propagate and handle them at the call site (which is already wrapped in a try/catch in provider.ts). This would simplify the function to:
const res = await fetchFn(`${baseURL}/models`, { headers, signal: AbortSignal.timeout(3 * 1000), }) if (!res.ok) throw new Error(`bad http status ${res.status}`) const parsed = OpenAICompatibleResponse.parse(await res.json())
The error messages would be less descriptive, but the call site already logs the error. Up to you whether the explicit error wrapping is worth the complexity.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@rekram1-node I’ve addressed the bot review comments and pushed the requested changes. Pls let me know if anything else is needed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@rekram1-node just a reminder this PR is a follow up that requires integration after merging |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yeah this is basically good to go, doing some fixes but this is on my plate for us to ship v soon! thank you for both of your work on this |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Just remembered, both LMStudio and Ollama supports the Responses api (which should be better?). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If the choice is to add that functionality, could that be added as a follow-up MR in order to get this feature out? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
440a837 to
aa52334
Compare
2a5420b to
a54a660
Compare
There was an error while loading. Please reload this page.
|
Merging into a separate branch that I'll play with for a bit and see if tweaks are needed, thanks for ur work on this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
some feedback I want to add here. right now the nonetheless, this is a very good step |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hi @rekram1-node have you had a chance to play with this feature? Do you think it's feasible to merge it into dev? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@waszqba if you are referencing the auto discovery of models from local llm servers- I've ported my original PR to this plugin https://github.com/goniz/opencode-local-provider |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
was this abandoned? My provider has more than 200 different models, it'd be quite a pain to configure manually. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I implemented this as a Plugin: https://github.com/goniz/opencode-local-provider |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The PR that would have been merged was auto closed by some stale script #13234 (comment) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Auto-discover models from OpenAI-compatible provider endpoints OpenCode displays models which aren't configured & don't exist in LM Studio Lmstudio Models are not listed correctly
There was an error while loading. Please reload this page.