blob: 0cc9941e180cb90eb0d8d62879b01e1f3d518804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
"""API routes for model listing and health checks."""
from __future__ import annotations
from starlette.requests import Request
from starlette.responses import JSONResponse
from ollama_web import llm
async def get_models(request: Request) -> JSONResponse:
"""Return available Ollama models as JSON."""
host = request.app.state.settings.ollama_host
models = llm.list_models(host=host)
return JSONResponse({"models": models})
async def get_model_capabilities(request: Request) -> JSONResponse:
"""Return capabilities for a single model via ``ollama.show()``.
The response contains the raw capability strings reported by ollama, e.g.
``{"capabilities": ["vision", "tools", "thinking"]}``. Unknown models or
connection failures return an empty list.
"""
model = request.path_params["model"]
host = request.app.state.settings.ollama_host
caps = sorted(llm.get_model_capabilities(model, host=host))
return JSONResponse({"capabilities": caps})
async def health(request: Request) -> JSONResponse:
"""Report Ollama server reachability."""
host = request.app.state.settings.ollama_host
models = llm.list_models(host=host)
reachable = models is not None
return JSONResponse({"reachable": reachable, "models": models})
|