fix(setup): filter LM Studio models by state == "loaded_instance"

LM Studio's /v1/models returns all downloaded models, not just loaded
ones. Use /api/v0/models with state filtering in both fetch_loaded_models()
and _fetch_local_models() so only RAM-resident models are shown as loaded.
This also restores the _choose_model() fallback that offers downloaded-but-
unloaded models when nothing is active in LM Studio.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-19 14:54:06 +02:00
parent 833d1445f0
commit 40aa934431
2 changed files with 62 additions and 8 deletions
+16 -2
View File
@@ -386,7 +386,14 @@ def fetch_loaded_models(provider: Provider) -> list[str]:
resp = httpx.get(f"{provider.base_url}/api/ps", timeout=3.0)
resp.raise_for_status()
return [m["name"] for m in resp.json().get("models", [])]
else:
elif provider.id == "lmstudio":
resp = httpx.get("http://localhost:1234/api/v0/models", timeout=3.0)
resp.raise_for_status()
return [
m["id"] for m in resp.json().get("data", [])
if m.get("state") == "loaded_instance"
]
else: # llamacpp — /models returns only the active loaded model
resp = httpx.get(f"{provider.base_url}/models", timeout=3.0)
resp.raise_for_status()
return [m["id"] for m in resp.json().get("data", [])]
@@ -407,7 +414,7 @@ def _show_local_model_status(provider: Provider) -> None:
def _fetch_local_models(provider: Provider) -> list[str]:
"""Return currently loaded/available models from a local provider's API."""
"""Return currently loaded models from a local provider's API."""
if not provider.base_url:
return []
try:
@@ -415,6 +422,13 @@ def _fetch_local_models(provider: Provider) -> list[str]:
resp = httpx.get(f"{provider.base_url}/api/tags", timeout=3.0)
resp.raise_for_status()
return [m["name"] for m in resp.json().get("models", [])]
elif provider.id == "lmstudio":
resp = httpx.get("http://localhost:1234/api/v0/models", timeout=3.0)
resp.raise_for_status()
return [
m["id"] for m in resp.json().get("data", [])
if m.get("state") == "loaded_instance"
]
else:
resp = httpx.get(f"{provider.base_url}/models", timeout=3.0)
resp.raise_for_status()