-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Load dynamic model list from LM Studio #9558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
95b0353
360e2a2
f3dbd12
de0de96
71a891f
b636218
86fad93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ../../ui/src/custom-elements.d.ts | ||
| /// <reference path="../../ui/src/custom-elements.d.ts" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,6 +199,9 @@ export async function get() { | |
| const disabled = new Set(config.disabled_providers ?? []) | ||
| const enabled = config.enabled_providers ? new Set(config.enabled_providers) : null | ||
| const kiloAllowed = (!enabled || enabled.has("kilo")) && !disabled.has("kilo") | ||
| const lmstudioDisabled = disabled.has("lmstudio") | ||
| const lmstudioEnabled = enabled ? enabled.has("lmstudio") : true | ||
| const lmstudioAllowed = lmstudioEnabled && !lmstudioDisabled | ||
|
|
||
| if (kiloAllowed && !providers["kilo"]) { | ||
| const kiloOptions = config.provider?.kilo?.options | ||
|
|
@@ -254,6 +257,39 @@ export async function get() { | |
| ModelCache.refresh("apertis", apertisFetchOptions).catch(() => {}) | ||
| } | ||
| } | ||
|
|
||
| // LM Studio dynamic model discovery | ||
| if (lmstudioAllowed) { | ||
| const lmstudioConfig = config.provider?.lmstudio?.options | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic looks pretty duplicated to below, please generalize if possible |
||
| const lmstudioBaseURL = lmstudioConfig?.baseURL ?? "http://127.0.0.1:1234/v1" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING:
|
||
| const lmstudioFetchOptions = { | ||
| ...(lmstudioConfig?.baseURL ? { baseURL: lmstudioConfig.baseURL } : {}), | ||
| ...(lmstudioConfig?.apiKey ? { apiKey: lmstudioConfig.apiKey } : {}), | ||
| } | ||
|
|
||
| try { | ||
| const lmstudioModels = await ModelCache.fetch("lmstudio", lmstudioFetchOptions).catch(() => ({})) | ||
| if (Object.keys(lmstudioModels).length > 0) { | ||
| if (!providers["lmstudio"]) { | ||
| providers["lmstudio"] = { | ||
| id: "lmstudio", | ||
| name: "LMStudio", | ||
| env: ["LMSTUDIO_API_KEY"], | ||
| api: lmstudioBaseURL, | ||
| npm: "@ai-sdk/openai-compatible", | ||
| models: lmstudioModels, | ||
| } | ||
| } else { | ||
| providers["lmstudio"].models = lmstudioModels | ||
| if (lmstudioConfig?.baseURL) { | ||
| providers["lmstudio"].api = lmstudioBaseURL | ||
| } | ||
| } | ||
| } | ||
| } catch (err) { | ||
| log.debug("lmstudio model fetch failed, using snapshot fallback", { error: err }) | ||
| } | ||
| } | ||
| } else if (!providers["apertis"]) { | ||
| const apertisConfig = config.provider?.apertis?.options | ||
| const apertisBaseURL = apertisConfig?.baseURL ?? "https://api.apertis.ai/v1" | ||
|
|
@@ -272,6 +308,39 @@ export async function get() { | |
| if (Object.keys(apertisModels).length === 0) { | ||
| ModelCache.refresh("apertis", apertisFetchOptions).catch(() => {}) | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't accept those changes without kilocode change markers and a changelog |
||
| // LM Studio dynamic model discovery (when kilo is not allowed) | ||
| if (lmstudioAllowed) { | ||
| const lmstudioConfig = config.provider?.lmstudio?.options | ||
| const lmstudioBaseURL = lmstudioConfig?.baseURL ?? "http://127.0.0.1:1234/v1" | ||
| const lmstudioFetchOptions = { | ||
| ...(lmstudioConfig?.baseURL ? { baseURL: lmstudioConfig.baseURL } : {}), | ||
| ...(lmstudioConfig?.apiKey ? { apiKey: lmstudioConfig.apiKey } : {}), | ||
| } | ||
|
|
||
| try { | ||
| const lmstudioModels = await ModelCache.fetch("lmstudio", lmstudioFetchOptions).catch(() => ({})) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we log errors? |
||
| if (Object.keys(lmstudioModels).length > 0) { | ||
| if (!providers["lmstudio"]) { | ||
| providers["lmstudio"] = { | ||
| id: "lmstudio", | ||
| name: "LMStudio", | ||
| env: ["LMSTUDIO_API_KEY"], | ||
| api: lmstudioBaseURL, | ||
| npm: "@ai-sdk/openai-compatible", | ||
| models: lmstudioModels, | ||
| } | ||
| } else { | ||
| providers["lmstudio"].models = lmstudioModels | ||
| if (lmstudioConfig?.baseURL) { | ||
| providers["lmstudio"].api = lmstudioBaseURL | ||
| } | ||
| } | ||
| } | ||
| } catch (err) { | ||
| log.debug("lmstudio model fetch failed, using snapshot fallback", { error: err }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return providers | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Refactor removes the Apertis API-key guard
Before this helper was generalized,
fetchApertisModels()returned early whenapiKeywas missing. After this change we still callhttps://api.apertis.ai/v1/modelswithout auth, andmodels.tsimmediately schedules a secondrefresh()because the cached result is empty. That turns an unconfigured provider into repeated failing network traffic on every startup.