File size: 1,473 Bytes
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
from app.services.enrichment.normalize import normalize_text
from app.services.enrichment.title_keywords import extract_title_and_keywords
from app.services.enrichment.summary import generate_summary
from app.services.enrichment.mindmap import generate_mindmap
# dùng cho regenerate / batch
async def run_pipeline(note: dict, tasks: list[str]):
    raw_text = note.get("raw_text") or ""
    if not raw_text.strip():
        # Nothing to process
        return note

    text = raw_text

    # 1️⃣ Normalize
    if "normalize" in tasks:
        try:
            text = await normalize_text(text)
            note["normalized_text"] = text
        except Exception:
            # Fail-safe: keep raw_text
            note["normalized_text"] = text

    # 2️⃣ Title + Keywords (same AI call)
    if "keywords" in tasks:
        try:
            title, keywords = await extract_title_and_keywords(text)
            if title:
                note["title"] = title
            if keywords:
                note["keywords"] = keywords
        except Exception:
            # Fail-safe: skip title & keywords
            pass

    # 3️⃣ Summary
    if "summary" in tasks:
        try:
            note["summary"] = await generate_summary(text)
        except Exception:
            pass

    # 4️⃣ Mindmap
    if "mindmap" in tasks:
        try:
            note["mindmap"] = await generate_mindmap(text)
        except Exception:
            pass

    return note