Refactor: Mem0-Sidecar nutzt lifespan statt deprecated on_event
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+8
-4
@@ -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 -----------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user