Files
Nat20-Notes/backend/app/routers/models.py
KansaiGaijin ca13989ca0
All checks were successful
Build and Push / build (push) Successful in 12m10s
per-campaign settings, default campaign folders, custom prompt fix
2026-07-21 17:46:37 +12:00

21 lines
808 B
Python

import requests
from fastapi import APIRouter, Query
from .. import database as db
router = APIRouter(prefix="/api/models", tags=["models"])
@router.get("/ollama")
def list_ollama_models(campaign_id: str = Query("default")):
"""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_campaign_settings(campaign_id)
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": []}