feat: add cv benchmark workflow and admin visibility

This commit is contained in:
2026-04-01 12:25:45 +02:00
parent 0551a525a8
commit 0d65835857
16 changed files with 832 additions and 95 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ python -m uvicorn app:app --host 127.0.0.1 --port 8001 --workers 1
The Dockerfile installs Tesseract OCR so scanned PDFs and supported images can be processed inside the container.
## API
- `GET /health` — health check and runtime capabilities
- `GET /health` — health check and runtime capabilities, including Ollama version/model metadata when configured
- `POST /summarize` — JSON body `{ "text": "...", "max_length": 150, "min_length": 30 }`
- `POST /extract-text` — multipart file upload, returns extracted text and OCR metadata
- `POST /cv/classify-block` — JSON body `{ "block": "..." }`, uses Ollama when `OLLAMA_MODEL` is configured
+27 -5
View File
@@ -63,6 +63,12 @@ def _key(text: str, max_length: int, min_length: int, top_skills: int) -> str:
return f"{h}:{max_length}:{min_length}:{top_skills}"
def _ollama_json(path: str):
req = urllib_request.Request(f"{OLLAMA_BASE_URL}{path}", method="GET")
with urllib_request.urlopen(req, timeout=5) as response:
return json.loads(response.read().decode("utf-8"))
def _ollama_status():
configured = bool(OLLAMA_MODEL)
if not configured:
@@ -71,27 +77,43 @@ def _ollama_status():
"ollama_reachable": False,
"ollama_model": None,
"ollama_model_available": False,
"ollama_version": None,
"ollama_installed_models": [],
"ollama_loaded_models": [],
"ollama_loaded_count": 0,
}
req = urllib_request.Request(f"{OLLAMA_BASE_URL}/api/tags", method="GET")
try:
with urllib_request.urlopen(req, timeout=5) as response:
body = json.loads(response.read().decode("utf-8"))
tags_body = _ollama_json("/api/tags")
version_body = _ollama_json("/api/version")
try:
ps_body = _ollama_json("/api/ps")
except Exception:
ps_body = {"models": []}
except Exception:
return {
"ollama_configured": True,
"ollama_reachable": False,
"ollama_model": OLLAMA_MODEL,
"ollama_model_available": False,
"ollama_version": None,
"ollama_installed_models": [],
"ollama_loaded_models": [],
"ollama_loaded_count": 0,
}
models = body.get("models") or []
names = {item.get("name") for item in models if isinstance(item, dict)}
models = tags_body.get("models") or []
names = sorted({item.get("name") for item in models if isinstance(item, dict) and item.get("name")})
loaded_models = sorted({item.get("name") for item in (ps_body.get("models") or []) if isinstance(item, dict) and item.get("name")})
return {
"ollama_configured": True,
"ollama_reachable": True,
"ollama_model": OLLAMA_MODEL,
"ollama_model_available": OLLAMA_MODEL in names,
"ollama_version": version_body.get("version"),
"ollama_installed_models": names,
"ollama_loaded_models": loaded_models,
"ollama_loaded_count": len(loaded_models),
}
+2
View File
@@ -32,6 +32,8 @@ def test_health_reports_runtime_without_ollama(monkeypatch):
assert payload["device"] == "cpu"
assert payload["ollama_configured"] is False
assert payload["ollama_model"] is None
assert payload["ollama_installed_models"] == []
assert payload["ollama_loaded_models"] == []
def test_classify_block_returns_structured_json(monkeypatch):