ragV98 commited on
Commit
7200af5
·
1 Parent(s): f675b06

merging docs for mistral

Browse files
Files changed (1) hide show
  1. components/generators/daily_feed.py +25 -16
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
- for doc in docs[:5]:
49
- tail_prompt = f"Topic: {topic}\n\n{doc.strip()}"
50
- print(f"\n📤 Prompt tail for LLaMA-3 8B:\n{tail_prompt[:300]}...\n")
51
- summary_block = call_mistral(base_prompt=BASE_PROMPT, tail_prompt=tail_prompt)
52
-
53
- if summary_block:
54
- for line in summary_block.splitlines():
55
- line = line.strip()
56
- if line.startswith("-") or line.startswith("–"):
57
- clean_summary = line.lstrip("-–").strip()
58
- if clean_summary:
59
- feed.append({
60
- "summary": clean_summary,
61
- "image_url": "https://source.unsplash.com/800x600/?news",
62
- "article_link": f"https://google.com/search?q={topic.replace(' ', '+')}"
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)