Spaces:
Runtime error
Runtime error
File size: 848 Bytes
b74c6ae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field
from app.auth import Ctx, get_ctx
from app.services import memory
router = APIRouter(prefix="/api/memory", tags=["memory"])
class FactIn(BaseModel):
value: str = Field(min_length=1, max_length=memory.MAX_VALUE)
@router.get("")
def list_facts(ctx: Ctx = Depends(get_ctx)):
return {"items": memory.list_facts(ctx.db, ctx.workspace.id), "limit": memory.MAX_FACTS}
@router.put("/{key}")
def put_fact(key: str, body: FactIn, ctx: Ctx = Depends(get_ctx)):
return memory.set_fact(ctx.db, ctx.workspace.id, key, body.value)
@router.delete("/{key}")
def delete_fact(key: str, ctx: Ctx = Depends(get_ctx)):
if not memory.delete_fact(ctx.db, ctx.workspace.id, key):
raise HTTPException(404, "Note not found")
return {"ok": True}
|