feat(ai-settings): auto-discover models for OpenAI-compatible providers - #2415
Open
Quim T. (espetro) wants to merge 1 commit into
Open
feat(ai-settings): auto-discover models for OpenAI-compatible providers#2415Quim T. (espetro) wants to merge 1 commit into
Quim T. (espetro) wants to merge 1 commit into
Conversation
Contributor
|
PR author is not in the allowed authors list. |
Contributor
|
All contributors have signed the CLA. Thank you! |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Closes #2411
Problem
For OpenAI-compatible endpoints (including Ollama and LM Studio), the Add Provider dialog showed a bundled models.dev catalog that is only ever a stale sample of what the user's endpoint actually serves. Users with local or proxied models had to paste exact model IDs by hand, and short catalogs (e.g. LM Studio's three entries) read as the complete list, leading users to conclude their loaded models were unsupported.
Implementation
Server (apps/server)
listProviderModelsinlib/clients/llm/list-models.ts: normalizes the base URL (strips trailing slash and trailing/v1), fetchesGET {base}/v1/modelswith optional Bearer auth, 15s timeout, and maps{ id, context_length }entries. Non-string ids are filtered out.createListModelRoutesinapi/routes/provider.ts, mounted atPOST /list-modelsinapi/routes/index.ts(separate from/test-providerto avoid the ugly/test-provider/modelspath).{ models: [], message }, so the client always keeps its free-form model entry UX.Client (apps/app)
listModelsinlib/llm-providers/listModels.ts: posts to the agent server and maps results toModelInfo, defaultingcontextLengthto 128000 when absent. Any failure returns an empty array (no throw).NewProviderDialog: auseDiscoveredModelshook auto-fetches (600ms debounce) whenever the provider type serves user-loaded models (openai-compatible,ollama,lmstudio) and a base URL is present. Discovered models replace the stale catalog in the picker; the free-form "paste exact ID" path is retained as fallback. A small refresh button next to the Model label re-triggers discovery. The "lists only common models" hint is suppressed once discovery returns results.USER_LOADED_MODEL_PROVIDERSset).Test plan
apps/server/src/lib/clients/llm/list-models.test.ts: happy path, missingdata, non-string ids, 401/500 throws, URL normalization (/v1,/v1/, trailing slash, bare host), Bearer header forwarding. All 15 tests pass.apps/app/lib/llm-providers/listModels.test.ts: mapping plus contextLength default, network failure returns[], non-200 returns[]. Passes.biome checkclean on all touched files;tsc --noEmitclean for touched files (pre-existing generated-graphql errors unchanged); full server and app suites show only pre-existing failures (verified identical on cleanmain).Out of scope
/modelsmetadata beyondcontext_length(not consistently present across providers).