42 lines
978 B
Plaintext
42 lines
978 B
Plaintext
import os
|
|
import subprocess
|
|
import time
|
|
|
|
|
|
def ask_hermes(text):
|
|
hermes_cli = os.getenv("HERMES_CLI", "/root/.local/bin/hermes")
|
|
|
|
start = time.perf_counter()
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
[hermes_cli, "--oneshot", text],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=180,
|
|
check=True
|
|
)
|
|
|
|
elapsed = time.perf_counter() - start
|
|
|
|
print(
|
|
f"[ALFRED] Hermes : {elapsed:.2f} secondes",
|
|
flush=True
|
|
)
|
|
|
|
return result.stdout.strip()
|
|
|
|
except subprocess.TimeoutExpired:
|
|
raise RuntimeError(
|
|
"Hermes n'a pas répondu dans le délai imparti."
|
|
)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
stderr = (e.stderr or "").strip()
|
|
stdout = (e.stdout or "").strip()
|
|
|
|
raise RuntimeError(
|
|
f"Hermes a échoué (code {e.returncode}): "
|
|
f"{stderr or stdout or 'aucun détail'}"
|
|
)
|