feat(setup,chat): detect actually-loaded local model via provider-specific API

For Ollama, /api/tags returns all installed models, not running ones.
Add fetch_loaded_models() using /api/ps for Ollama (and /v1/models for
LM Studio/llama.cpp, which already return only loaded models).

_show_local_model_status() now calls fetch_loaded_models() so the
setup wizard correctly shows only in-memory models for Ollama.

At chat session startup, local providers warn when the configured model
is not currently loaded, or when nothing is loaded at all.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
curo1305
2026-05-19 14:46:54 +02:00
parent cb390ad6af
commit 833d1445f0
3 changed files with 77 additions and 4 deletions
+11
View File
@@ -25,6 +25,7 @@ from pyra.plugins.executor import ToolExecutor
from pyra.plugins.registry import PluginRegistry
from pyra.security.injection import scan_response
from pyra.setup.providers import get_provider
from pyra.setup.wizard import fetch_loaded_models
from pyra.utils.paths import pyra_home
_HISTORY_FILE = pyra_home() / ".chat_history"
@@ -176,6 +177,16 @@ def start_chat() -> None:
"[dim]Type /help for commands, /quit to exit.[/dim]"
)
if provider.group == "Local":
loaded = fetch_loaded_models(provider)
if not loaded:
render_info(f"No model currently loaded in {provider.display_name}.")
elif cfg.ai.model not in loaded:
render_info(
f"Model '{cfg.ai.model}' not loaded in {provider.display_name}. "
f"Loaded: {', '.join(loaded)}"
)
_flags: dict = {"use_tools": True}
while True:
+18 -1
View File
@@ -377,9 +377,26 @@ def _check_local_server(provider: Provider) -> None:
# "retry" → loop
def fetch_loaded_models(provider: Provider) -> list[str]:
"""Return models currently loaded in RAM from a local provider's API."""
if not provider.base_url:
return []
try:
if provider.id == "ollama":
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:
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", [])]
except Exception:
return []
def _show_local_model_status(provider: Provider) -> None:
"""Print a one-line status showing which models are currently loaded."""
models = _fetch_local_models(provider)
models = fetch_loaded_models(provider)
if not models:
console.print(" [yellow]No model currently loaded[/yellow]")
elif len(models) == 1: