bichnhan2701 commited on
Commit
ab5e094
·
1 Parent(s): 7d65af7

Update erich job

Browse files
Files changed (1) hide show
  1. 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
- # 1️⃣ Normalize
 
 
 
 
26
  if "normalize" in tasks:
27
- text = await normalize_text(note.get("raw_text", ""))
28
- update_note(note_id, {
29
- "normalized_text": text,
30
- "status": NoteStatus.normalize_done,
31
- "updated_at": now_ts(),
32
- })
33
- else:
34
- text = note.get("raw_text", "")
35
-
36
- # 2️⃣ Title + Keywords
 
 
 
37
  if "keywords" in tasks:
38
- title, keywords = await extract_title_and_keywords(text)
39
- update_note(note_id, {
40
- "title": title,
41
- "keywords": keywords,
42
- "status": NoteStatus.keywords_done,
43
- "updated_at": now_ts(),
44
- })
45
-
46
- # 3️⃣ Summary
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  if "summary" in tasks:
48
- summary = await generate_summary(text)
49
- update_note(note_id, {
50
- "summary": summary,
51
- "status": NoteStatus.summary_done,
52
- "updated_at": now_ts(),
53
- })
54
-
55
- # 4️⃣ Mindmap
 
 
 
 
56
  if "mindmap" in tasks:
57
- mindmap = await generate_mindmap(text)
58
- update_note(note_id, {
59
- "mindmap": mindmap,
60
- "status": NoteStatus.mindmap_done,
61
- "updated_at": now_ts(),
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(),