Spaces:
Running
Running
| from fastapi import APIRouter, BackgroundTasks | |
| from pydantic import BaseModel | |
| from typing import List, Optional | |
| from app.services.note_store import create_note | |
| from app.jobs.async_enrichment_job import enrich_note | |
| from app.models.enums import NoteType, NoteStatus | |
| from app.utils.id import new_id | |
| from app.utils.time import now_ts | |
| router = APIRouter(prefix="/notes", tags=["notes"]) | |
| class CreateTextNoteRequest(BaseModel): | |
| raw_text: str | |
| folder_id: Optional[str] = None | |
| generate: List[str] = [] | |
| async def create_text_note(req: CreateTextNoteRequest, bg: BackgroundTasks): | |
| note_id = new_id() | |
| now = now_ts() | |
| has_enrichment = bool(req.generate) | |
| note = { | |
| "note_id": note_id, | |
| "type": NoteType.text, | |
| "raw_text": req.raw_text, | |
| "folder_id": req.folder_id, | |
| "status": NoteStatus.processing if has_enrichment else NoteStatus.created, | |
| "created_at": now, | |
| "updated_at": now, | |
| } | |
| create_note(note) | |
| if has_enrichment: | |
| bg.add_task(enrich_note, note_id, req.generate) | |
| return { | |
| "note_id": note_id, | |
| "status": note["status"], | |
| } |