Refactor: Mem0-Sidecar nutzt lifespan statt deprecated on_event

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hitonabi
2026-06-27 19:29:44 +02:00
parent 05bef8642d
commit 6d552b035a
+8 -4
View File
@@ -20,6 +20,7 @@ Bind: 127.0.0.1 (nur lokal; MC2 proxyt nach außen).
import logging
import os
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
@@ -94,7 +95,6 @@ def build_memory() -> Memory:
return m
app = FastAPI(title="MC2 Mem0 Sidecar")
_mem: Memory | None = None
@@ -105,14 +105,18 @@ def mem() -> Memory:
return _mem
@app.on_event("startup")
def _startup() -> None:
@asynccontextmanager
async def lifespan(_app: FastAPI):
logging.basicConfig(level=logging.INFO)
try:
mem()
mem() # Memory beim Start aufbauen (Chroma öffnen, Modelle anpingen)
log.info("Mem0 bereit (chroma=%s, embed=%s, llm=%s)", CHROMA_PATH, EMBED_MODEL, LLM_MODEL)
except Exception:
log.exception("Mem0-Init fehlgeschlagen (Dienst läuft, /health meldet down)")
yield
app = FastAPI(title="MC2 Mem0 Sidecar", lifespan=lifespan)
# --- Mapping Mem0 <-> MC2-API-Form -----------------------------------------------