import requests from fastapi import APIRouter from .. import database as db router = APIRouter(prefix="/api/models", tags=["models"]) @router.get("/ollama") def list_ollama_models(): """List models already pulled on the configured Ollama host, so the setup wizard can offer a dropdown instead of asking the user to type a tag blind.""" settings = db.get_settings() host = settings.get("ollama_host", "http://host.docker.internal:11434") try: resp = requests.get(f"{host.rstrip('/')}/api/tags", timeout=5) resp.raise_for_status() return {"ok": True, "models": [m["name"] for m in resp.json().get("models", [])]} except Exception as e: return {"ok": False, "error": str(e), "models": []}