Spaces:
Running
Running
File size: 1,257 Bytes
7402e0f 7d65af7 7402e0f 7d65af7 7402e0f 7d65af7 7402e0f |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
from app.models.enums import NoteStatus
from app.utils.time import now_ts
from fastapi import APIRouter, BackgroundTasks, HTTPException
from pydantic import BaseModel
from typing import List
from app.services.note_store import get_note, update_note
from app.jobs.async_enrichment_job import enrich_note
router = APIRouter(prefix="/notes", tags=["notes"])
class RegenerateRequest(BaseModel):
generate: List[str]
@router.post("/{note_id}/regenerate")
def regenerate_note(note_id: str, req: RegenerateRequest, bg: BackgroundTasks):
note = get_note(note_id)
if not note:
raise HTTPException(404, "Note not found")
allowed = {"normalize", "keywords", "summary", "mindmap"}
if not set(req.generate).issubset(allowed):
raise HTTPException(400, "Invalid generate task, generate list must not be empty")
# mark processing immediately
update_note(note_id, {
"status": NoteStatus.processing,
"normalized_text": None,
"title": None,
"keywords": None,
"summary": None,
"mindmap": None,
"updated_at": now_ts(),
})
bg.add_task(enrich_note, note_id, req.generate)
return {
"note_id": note_id,
"status": NoteStatus.processing,
}
|