Spaces:
Sleeping
Sleeping
Commit
·
ab5e094
1
Parent(s):
7d65af7
Update erich job
Browse files- app/jobs/async_enrichment_job.py +63 -35
app/jobs/async_enrichment_job.py
CHANGED
|
@@ -4,7 +4,6 @@ from app.services.enrichment.normalize import normalize_text
|
|
| 4 |
from app.services.enrichment.summary import generate_summary
|
| 5 |
from app.services.enrichment.title_keywords import extract_title_and_keywords
|
| 6 |
from app.services.note_store import get_note, update_note
|
| 7 |
-
from app.services.enrichment.batch_pipeline import run_pipeline
|
| 8 |
from app.models.enums import NoteStatus
|
| 9 |
from app.utils.time import now_ts
|
| 10 |
|
|
@@ -22,45 +21,74 @@ async def enrich_note(note_id: str, tasks: list[str]):
|
|
| 22 |
})
|
| 23 |
|
| 24 |
try:
|
| 25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
if "normalize" in tasks:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
if "keywords" in tasks:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if "summary" in tasks:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
if "mindmap" in tasks:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
|
|
|
| 64 |
update_note(note_id, {
|
| 65 |
"status": NoteStatus.ready,
|
| 66 |
"updated_at": now_ts(),
|
|
|
|
| 4 |
from app.services.enrichment.summary import generate_summary
|
| 5 |
from app.services.enrichment.title_keywords import extract_title_and_keywords
|
| 6 |
from app.services.note_store import get_note, update_note
|
|
|
|
| 7 |
from app.models.enums import NoteStatus
|
| 8 |
from app.utils.time import now_ts
|
| 9 |
|
|
|
|
| 21 |
})
|
| 22 |
|
| 23 |
try:
|
| 24 |
+
# ---------- TEXT SOURCE ----------
|
| 25 |
+
raw_text = note.get("raw_text", "").strip()
|
| 26 |
+
text = raw_text
|
| 27 |
+
|
| 28 |
+
# ---------- 1️⃣ Normalize ----------
|
| 29 |
if "normalize" in tasks:
|
| 30 |
+
try:
|
| 31 |
+
normalized = await normalize_text(raw_text)
|
| 32 |
+
if normalized and len(normalized) > 10:
|
| 33 |
+
text = normalized
|
| 34 |
+
update_note(note_id, {
|
| 35 |
+
"normalized_text": normalized,
|
| 36 |
+
"status": NoteStatus.normalize_done,
|
| 37 |
+
"updated_at": now_ts(),
|
| 38 |
+
})
|
| 39 |
+
except Exception:
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
# ---------- 2️⃣ Title + Keywords ----------
|
| 43 |
if "keywords" in tasks:
|
| 44 |
+
try:
|
| 45 |
+
title, keywords = await extract_title_and_keywords(text)
|
| 46 |
+
|
| 47 |
+
updates = {
|
| 48 |
+
"status": NoteStatus.keywords_done,
|
| 49 |
+
"updated_at": now_ts(),
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# 🔥 FAIL-SAFE
|
| 53 |
+
if title and title.strip():
|
| 54 |
+
updates["title"] = title.strip()
|
| 55 |
+
elif note.get("summary"):
|
| 56 |
+
updates["title"] = note["summary"].split(".")[0][:120]
|
| 57 |
+
|
| 58 |
+
updates["keywords"] = keywords or []
|
| 59 |
+
|
| 60 |
+
update_note(note_id, updates)
|
| 61 |
+
|
| 62 |
+
except Exception:
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
# ---------- 3️⃣ Summary ----------
|
| 66 |
if "summary" in tasks:
|
| 67 |
+
try:
|
| 68 |
+
summary = await generate_summary(text)
|
| 69 |
+
if summary:
|
| 70 |
+
update_note(note_id, {
|
| 71 |
+
"summary": summary,
|
| 72 |
+
"status": NoteStatus.summary_done,
|
| 73 |
+
"updated_at": now_ts(),
|
| 74 |
+
})
|
| 75 |
+
except Exception:
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
# ---------- 4️⃣ Mindmap ----------
|
| 79 |
if "mindmap" in tasks:
|
| 80 |
+
try:
|
| 81 |
+
mindmap = await generate_mindmap(text)
|
| 82 |
+
if mindmap:
|
| 83 |
+
update_note(note_id, {
|
| 84 |
+
"mindmap": mindmap,
|
| 85 |
+
"status": NoteStatus.mindmap_done,
|
| 86 |
+
"updated_at": now_ts(),
|
| 87 |
+
})
|
| 88 |
+
except Exception:
|
| 89 |
+
pass
|
| 90 |
|
| 91 |
+
# ---------- DONE ----------
|
| 92 |
update_note(note_id, {
|
| 93 |
"status": NoteStatus.ready,
|
| 94 |
"updated_at": now_ts(),
|