Console Voice Assistant (Jervis): text prompt box -> local LLM agent (/voice proxies to .13:8501)

This commit is contained in:
2026-08-30 14:55:39 +10:00
parent a347aefdff
commit d68f6a4304
4 changed files with 67 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ from zoneinfo import ZoneInfo
MELB = ZoneInfo("Australia/Melbourne")
import json
import os
import httpx
from pathlib import Path
from typing import Annotated
@@ -329,6 +330,39 @@ async def files_upload(request: Request, file: Annotated[UploadFile, File()]) ->
)
VOICE_AGENT = os.getenv("VOICE_AGENT_URL", "http://192.168.20.13:8501")
@app.get("/voice", response_class=HTMLResponse)
async def voice_page(request: Request) -> HTMLResponse:
user = await _current_user(request)
if user is None:
return RedirectResponse("/login", status_code=303)
return templates.TemplateResponse(request, "voice.html", {"user": user})
@app.post("/voice", response_class=HTMLResponse)
async def voice_send(request: Request, message: Annotated[str, Form()]) -> HTMLResponse:
user = await _current_user(request)
if user is None:
return RedirectResponse("/login", status_code=303)
command = message.strip()
error = reply = None
if command:
try:
async with httpx.AsyncClient(timeout=60) as client:
r = await client.post(f"{VOICE_AGENT}/voice", json={"text": command})
r.raise_for_status()
reply = r.json().get("reply") or r.json().get("text")
except Exception as exc: # noqa: BLE001
logger.warning("voice agent call failed", exc_info=True)
error = f"Voice assistant unavailable: {type(exc).__name__}"
return templates.TemplateResponse(
request, "voice.html", {"user": user, "command": command, "reply": reply, "error": error}
)
@app.get("/admin", response_class=HTMLResponse)
async def admin_panel(request: Request) -> HTMLResponse:
user = await _current_user(request)