feat: persona chat loop, web UI, and local (Ollama) embeddings

Phase 1 — persona + persistent memory chat loop:
- lyra/persona.py + personas/lyra.md: editable identity/voice (friend-first,
  honest, never invents poker math)
- lyra/chat.py: turn loop assembling persona + cross-session recall + recent
  context, persisting both sides to SQLite
- lyra/session.py, lyra/__main__.py: session lifecycle + `lyra` REPL

Phase 1.25 — reuse the old web UI:
- vendored the prior single-page UI into lyra/web/static, repointed to
  same-origin
- lyra/web/server.py (FastAPI): serves the UI and backs its endpoint contract
  (/v1/chat/completions, session CRUD, health, inert thinking-stream) with the
  new chat loop + memory; SQLite stays the single source of truth
- `lyra-web` console script

Local backends — test for free, no OpenAI key:
- llm.embed routes via EMBED_BACKEND (cloud=OpenAI, local=Ollama /api/embed)
- simplified UI backend selector to Local (Ollama) / Cloud (OpenAI), default local
- memory connection opened check_same_thread=False for the threaded server

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-15 18:36:31 +00:00
parent 6d88505697
commit 3b9e0bb1e0
17 changed files with 2973 additions and 4 deletions
+20
View File
@@ -0,0 +1,20 @@
"""Persona: Lyra's identity and voice, loaded from an editable markdown prompt.
The prompt lives in `personas/<name>.md` so it can be tuned without touching
code. `LYRA_PERSONA` selects which file to load (default: "lyra").
"""
from __future__ import annotations
import os
from functools import lru_cache
from pathlib import Path
_PERSONA_DIR = Path(__file__).parent / "personas"
@lru_cache(maxsize=None)
def system_prompt(name: str | None = None) -> str:
"""Return the persona system prompt. Cached; pass a name to override env."""
name = name or os.getenv("LYRA_PERSONA", "lyra")
path = _PERSONA_DIR / f"{name}.md"
return path.read_text(encoding="utf-8").strip()