feat: Langzeit-Erinnerungen (#3b) und WebSocket-Streaming-Chat (#4, erster Increment)
#3b Langzeit-Erinnerungen: - Store: memories-Tabelle + add/get/delete_memory (pro Nutzer) - API: GET/POST/DELETE /api/me/memories - chat.py injiziert Nutzer-Erinnerungen als System-Kontext ins LLM (sessionunabhaengig) - ?debug zeigt memories_len #4 Echtzeit (erster Increment): - WS /ws/chat: dauerhafter Kanal, Event-Folge ack -> semantic -> audio (binaer) -> done - Auth (Token-Query), Session-Gedaechtnis und Erinnerungen wie bei POST /api/chat - Fehler als error-Event (422/403/502) - Tests: 38 gruen (Erinnerungs-CRUD/Injektion, WebSocket-Streaming/Auth) - Doku aktualisiert (README, BEDIENUNGSANLEITUNG, Architektur) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
16a964032e
commit
531b57e08d
12 changed files with 389 additions and 9 deletions
|
|
@ -58,23 +58,32 @@ async def chat(
|
|||
orchestrator = build_orchestrator(route)
|
||||
output = await resolve_output_endpoint(route)
|
||||
# Gespraechsverlauf laden (nur bei gesetzter session_id -> sonst zustandslos).
|
||||
history = (
|
||||
conversation = (
|
||||
store.get_recent_messages(session_id, settings.history_max_messages)
|
||||
if session_id
|
||||
else []
|
||||
)
|
||||
# Langzeit-Erinnerungen sind nutzerbezogen und gelten auch ohne Session.
|
||||
memories = store.get_memories(user.id)
|
||||
except SessionOwnershipError as exc:
|
||||
raise HTTPException(status_code=403, detail=str(exc))
|
||||
except RoutingError as exc:
|
||||
raise HTTPException(status_code=422, detail=str(exc))
|
||||
|
||||
llm_context = list(conversation)
|
||||
if memories:
|
||||
memory_text = "Was du ueber den Nutzer weisst:\n" + "\n".join(
|
||||
f"- {m.content}" for m in memories
|
||||
)
|
||||
llm_context = [{"role": "system", "content": memory_text}] + llm_context
|
||||
|
||||
try:
|
||||
trace, audio = await orchestrator.chat_text(
|
||||
payload.text,
|
||||
language=route.language,
|
||||
voice=voice,
|
||||
output=output,
|
||||
history=history,
|
||||
history=llm_context,
|
||||
)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=502, detail=str(exc))
|
||||
|
|
@ -90,7 +99,8 @@ async def chat(
|
|||
"ok": True,
|
||||
"voice": voice,
|
||||
"route": route.as_dict(),
|
||||
"history_len": len(history),
|
||||
"history_len": len(conversation),
|
||||
"memories_len": len(memories),
|
||||
"trace": {
|
||||
"raw_transcript": trace.raw_transcript,
|
||||
"cleaned_transcript": trace.cleaned_transcript,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue