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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user