fixed memmory
This commit is contained in:
@@ -5,6 +5,8 @@ from pydantic import BaseModel, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.base import get_db
|
||||
from app.db.models import ChatSession
|
||||
from app.memory.extract import extract_after_turn
|
||||
from app.memory.service import MemoryService
|
||||
|
||||
router = APIRouter()
|
||||
@@ -26,6 +28,13 @@ class SessionSummaryUpdate(BaseModel):
|
||||
message_count: int = 0
|
||||
|
||||
|
||||
class ExtractRequest(BaseModel):
|
||||
session_id: int
|
||||
user_text: str = Field(min_length=1)
|
||||
assistant_text: str = ""
|
||||
force: bool = False
|
||||
|
||||
|
||||
@router.get("/memory")
|
||||
def get_memory_snapshot(
|
||||
session_id: int | None = None,
|
||||
@@ -85,6 +94,23 @@ def forget_fact(memory_id: int, db: Session = Depends(get_db)) -> dict[str, Any]
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@router.post("/memory/extract")
|
||||
async def extract_memories(
|
||||
payload: ExtractRequest,
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict:
|
||||
session = db.get(ChatSession, payload.session_id)
|
||||
if not session:
|
||||
raise HTTPException(status_code=404, detail="Session not found")
|
||||
return await extract_after_turn(
|
||||
db,
|
||||
payload.session_id,
|
||||
payload.user_text,
|
||||
payload.assistant_text,
|
||||
force=payload.force,
|
||||
)
|
||||
|
||||
|
||||
@router.put("/memory/sessions/{session_id}/summary")
|
||||
def update_session_summary(
|
||||
session_id: int,
|
||||
|
||||
Reference in New Issue
Block a user