NoteServicesAPI / app /api /notes /notes_audio.py
bichnhan2701's picture
Update note services logic
7402e0f
raw
history blame
1.15 kB
from fastapi import APIRouter, BackgroundTasks, HTTPException
from pydantic import BaseModel
from typing import Dict, List, Optional
from app.services.note_store import create_note
from app.jobs.enrichment_job import enrich_note
from app.models.enums import NoteType, NoteStatus
from app.utils.time import now_ts
router = APIRouter(prefix="/internal/notes", tags=["internal"])
class CreateAudioNoteRequest(BaseModel):
note_id: str
raw_text: str
metadata: Dict
generate: List[str] = []
@router.post("/audio")
async def create_audio_note(req: CreateAudioNoteRequest, bg: BackgroundTasks):
now = now_ts()
has_enrichment = bool(req.generate)
note = {
"note_id": req.note_id,
"type": NoteType.audio,
"raw_text": req.raw_text,
"metadata": req.metadata,
"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, req.note_id, req.generate)
return {
"note_id": req.note_id,
"status": note["status"],
}