feat(agent): log answer comments

This commit is contained in:
2026-09-17 00:02:31 +02:00
parent b42c326d7f
commit af8bfcaa6a
10 changed files with 241 additions and 55 deletions
+40
View File
@@ -124,6 +124,18 @@ class RatingResponse(StrictModel):
accepted: Literal[True] = True
class CommentRequest(StrictModel):
request_id: str = Field(pattern=r"^[A-Za-z0-9._:-]{1,128}$")
comment: str = Field(min_length=1, max_length=2000)
class CommentResponse(StrictModel):
api_version: Literal["v1"] = API_VERSION
request_id: str
comment_id: int
accepted: Literal[True] = True
class AppState:
def __init__(self) -> None:
self.cfg: Config | None = None
@@ -435,6 +447,34 @@ def rate_answer(req: RatingRequest, request: Request) -> RatingResponse:
return RatingResponse(request_id=req.request_id, rating=req.rating)
@app.post(
"/v1/comments",
response_model=CommentResponse,
dependencies=[Depends(require_api_access)],
)
def comment_answer(req: CommentRequest, request: Request) -> CommentResponse:
rag: AppState = request.app.state.rag
audit = rag.get_audit()
if audit is None:
raise HTTPException(status_code=503, detail="Kommentare sind nicht aktiviert.")
comment = req.comment.strip()
if not comment:
raise HTTPException(status_code=422, detail="Kommentar darf nicht leer sein.")
try:
comment_id = audit.record_comment(req.request_id, comment)
except KeyError as exc:
raise HTTPException(status_code=404, detail="Antwort nicht gefunden.") from exc
except Exception as exc:
logger.exception("Kommentar fehlgeschlagen request_id=%s", req.request_id)
raise HTTPException(
status_code=503, detail="Kommentar konnte nicht gespeichert werden."
) from exc
return CommentResponse(
request_id=req.request_id,
comment_id=comment_id,
)
def _reindex(request: Request) -> dict:
rag: AppState = request.app.state.rag
cfg = rag.ensure()