52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""Router RAG thérapeutique (médical) : corpus + authoring + test retrieval."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter
|
|
from pydantic import BaseModel
|
|
|
|
from kazeia_central.core.context import Ctx
|
|
from . import service as svc
|
|
|
|
|
|
class _Doc(BaseModel):
|
|
text: str
|
|
|
|
|
|
class _Query(BaseModel):
|
|
text: str
|
|
|
|
|
|
def make_router(ctx: Ctx) -> APIRouter:
|
|
r = APIRouter(prefix="/api/rag", tags=["rag"])
|
|
g, now = ctx.guard, ctx.now_ms
|
|
|
|
# Littéraux (status) et sous-chemins avant /{serial} nu — gérés par la profondeur.
|
|
@r.get("/{serial}/status")
|
|
def rag_status(serial: str):
|
|
return g(lambda: svc.status(ctx.adb, serial))
|
|
|
|
@r.get("/{serial}")
|
|
def rag_docs(serial: str):
|
|
return g(lambda: svc.list_docs(ctx.adb, serial))
|
|
|
|
@r.get("/{serial}/doc/{source}")
|
|
def rag_get(serial: str, source: str):
|
|
return g(lambda: svc.get_doc(ctx.adb, serial, source))
|
|
|
|
@r.put("/{serial}/doc/{source}")
|
|
def rag_put(serial: str, source: str, body: _Doc):
|
|
return g(lambda: svc.upsert_doc(ctx.adb, ctx.store, serial, source, body.text,
|
|
now=now(), actor=ctx.operator))
|
|
|
|
@r.delete("/{serial}/doc/{source}")
|
|
def rag_delete(serial: str, source: str):
|
|
return g(lambda: svc.delete_doc(ctx.adb, ctx.store, serial, source,
|
|
now=now(), actor=ctx.operator))
|
|
|
|
@r.post("/{serial}/query")
|
|
def rag_query(serial: str, body: _Query):
|
|
return g(lambda: svc.query(ctx.adb, serial, body.text))
|
|
|
|
return r
|