Spaces:
Sleeping
Sleeping
File size: 1,575 Bytes
7402e0f 7d65af7 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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.async_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)
allowed = {"normalize", "keywords", "summary", "mindmap"}
if not set(req.generate).issubset(allowed):
raise HTTPException(400, "Invalid generate task, generate list must not be empty")
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,
}
if has_enrichment:
note.update({
"normalized_text": None,
"title": None,
"keywords": None,
"summary": None,
"mindmap": None,
})
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"],
}
|