merging docs for mistral
Browse files
components/generators/daily_feed.py
CHANGED
@@ -45,25 +45,34 @@ BASE_PROMPT = (
|
|
45 |
|
46 |
def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
|
47 |
feed = []
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return feed
|
65 |
|
66 |
|
|
|
67 |
# ⚡ Generate and cache daily feed
|
68 |
def generate_and_cache_daily_feed(documents: List[Document]):
|
69 |
index = VectorStoreIndex.from_documents(documents)
|
|
|
45 |
|
46 |
def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
|
47 |
feed = []
|
48 |
+
if not docs:
|
49 |
+
return feed
|
50 |
+
|
51 |
+
# 🧠 Merge all docs with separators
|
52 |
+
merged_context = "\n\n---\n\n".join(doc.strip() for doc in docs)
|
53 |
+
tail_prompt = f"Topic: {topic}\n\n{merged_context}"
|
54 |
+
|
55 |
+
print(f"\n📤 Prompt tail for summarization:\n{tail_prompt[:500]}...\n")
|
56 |
+
|
57 |
+
# 🧠 Single call to summarizer
|
58 |
+
summary_block = call_mistral(base_prompt=BASE_PROMPT, tail_prompt=tail_prompt)
|
59 |
+
|
60 |
+
if summary_block:
|
61 |
+
for line in summary_block.splitlines():
|
62 |
+
line = line.strip()
|
63 |
+
if line.startswith("-") or line.startswith("–"):
|
64 |
+
clean_summary = line.lstrip("-–").strip()
|
65 |
+
if clean_summary:
|
66 |
+
feed.append({
|
67 |
+
"summary": clean_summary,
|
68 |
+
"image_url": "https://source.unsplash.com/800x600/?news",
|
69 |
+
"article_link": f"https://google.com/search?q={topic.replace(' ', '+')}"
|
70 |
+
})
|
71 |
+
|
72 |
return feed
|
73 |
|
74 |
|
75 |
+
|
76 |
# ⚡ Generate and cache daily feed
|
77 |
def generate_and_cache_daily_feed(documents: List[Document]):
|
78 |
index = VectorStoreIndex.from_documents(documents)
|