feat(harness): tht ollama ensure CLI command (hard-fail preflight)
This commit is contained in:
@@ -5,8 +5,17 @@ error (the caller refuses the session). "Load" = warm the already-installed mode
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import typer
|
||||
|
||||
from tht.cli.config_cmd import CONFIG_OPT
|
||||
from tht.cli.schema_cmd import _load_config_or_exit
|
||||
|
||||
ollama_app = typer.Typer(help="Ollama (embeddings) -- preflight.")
|
||||
|
||||
|
||||
# --- low-level ops (real implementations; injected as fakes in tests) ----------
|
||||
@@ -118,3 +127,29 @@ def ensure_ollama(
|
||||
"error": f"warm del modello '{emb.model}' fallito: {e}"}
|
||||
|
||||
return {"ok": True, "server": server_state, "model": "warmed", "model_name": emb.model}
|
||||
|
||||
|
||||
# --- CLI command ----------
|
||||
|
||||
|
||||
@ollama_app.command("ensure")
|
||||
def ensure_cmd(
|
||||
timeout: int = typer.Option(60, "--timeout", help="Secondi di attesa per l'avvio di Ollama."),
|
||||
no_start: bool = typer.Option(False, "--no-start", help="Non avviare Ollama (solo verifica)."),
|
||||
json_out: bool = typer.Option(False, "--json", help="Emetti JSON puro su stdout."),
|
||||
config: Path = CONFIG_OPT,
|
||||
) -> None:
|
||||
"""Assicura Ollama attivo + modello di embedding caricato; errore se non possibile."""
|
||||
cfg = _load_config_or_exit(config)
|
||||
result = ensure_ollama(cfg, timeout=timeout, no_start=no_start)
|
||||
if json_out:
|
||||
typer.echo(json.dumps(result, ensure_ascii=False))
|
||||
elif result["ok"]:
|
||||
typer.secho(
|
||||
f"OK: Ollama {result['server']}, modello {result['model_name']} {result['model']}.",
|
||||
fg=typer.colors.GREEN,
|
||||
)
|
||||
else:
|
||||
typer.secho(f"ERRORE [{result['stage']}]: {result['error']}", fg=typer.colors.RED, err=True)
|
||||
if not result["ok"]:
|
||||
raise typer.Exit(code=1)
|
||||
|
||||
Reference in New Issue
Block a user