ragV98 commited on
Commit
93ca074
ยท
1 Parent(s): c86bfda

prompt revision 6

Browse files
Files changed (1) hide show
  1. components/generators/daily_feed.py +28 -15
components/generators/daily_feed.py CHANGED
@@ -33,18 +33,22 @@ HEADERS = {
33
  # ๐Ÿง  Build Mistral-style instruction prompt
34
  def build_prompt(content: str, topic: str) -> str:
35
  base_instruction = (
36
- "You are Nuseโ€™s official news summarizer โ€” factual, concise, and engaging.\n"
37
- "Summarize the following article in 25โ€“30 words with 1โ€“2 emojis.\n"
38
- "The given content might contain multiple new items, so summarise each news item in 25-30 words and arranage them one line after the other starting them with a -"
39
- "For example:"
40
- " -India wins the biggest...."
41
- " -The U.S trade tarrifs...."
42
- " -Netanyahu agrees for a ceasefire...."
43
- "Return only the summary."
 
 
 
44
  )
45
  tail = f"Topic: {topic}\n\n{content.strip()}"
46
  return f"<s>[INST]{base_instruction}\n\n{tail}[/INST]</s>"
47
 
 
48
  # ๐Ÿ” Call Mistral using HF Inference Endpoint
49
  def call_mistral(prompt: str) -> Optional[str]:
50
  headers = {
@@ -83,15 +87,24 @@ def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
83
  for doc in docs[:5]:
84
  prompt = build_prompt(doc, topic)
85
  print("\n๐Ÿ“ค Prompt sent to Mistral:\n", prompt[:300], "...\n")
86
- summary = call_mistral(prompt)
87
- if summary:
88
- feed.append({
89
- "summary": summary,
90
- "image_url": "https://source.unsplash.com/800x600/?news",
91
- "article_link": "https://google.com/search?q=" + topic.replace(" ", "+")
92
- })
 
 
 
 
 
 
 
 
93
  return feed
94
 
 
95
  # โšก Generate and cache daily feed
96
  def generate_and_cache_daily_feed(documents: List[Document]):
97
  index = VectorStoreIndex.from_documents(documents)
 
33
  # ๐Ÿง  Build Mistral-style instruction prompt
34
  def build_prompt(content: str, topic: str) -> str:
35
  base_instruction = (
36
+ "You are Nuseโ€™s official news summarizer โ€” insightful, punchy, and always on point. ๐Ÿง โœจ\n"
37
+ "Your job is to scan the content below and extract the key news items. For each item, craft a crisp summary (25โ€“30 words), add 1โ€“2 fitting emojis, and make it pop.\n"
38
+ "List each summary on a new line starting with a dash (-). This is how Nuse keeps it clean and scannable.\n"
39
+ "\n"
40
+ "Example format:\n"
41
+ "- India stuns Australia in a last-ball thriller at the World Cup finals ๐Ÿ๐Ÿ‡ฎ๐Ÿ‡ณ\n"
42
+ "- U.S. imposes sweeping tariffs on Chinese tech giants, rattling global markets ๐Ÿ“‰๐Ÿ‡บ๐Ÿ‡ธ\n"
43
+ "- Ceasefire breakthrough: Netanyahu bows to pressure after week-long escalation ๐Ÿ”ฅ๐Ÿ•Š๏ธ\n"
44
+ "\n"
45
+ "Be sharp. Be brief. No fluff. No preambles. Just the summaries.\n"
46
+ "Return only the final summary block โ€” no extra commentary, no prompt repetition."
47
  )
48
  tail = f"Topic: {topic}\n\n{content.strip()}"
49
  return f"<s>[INST]{base_instruction}\n\n{tail}[/INST]</s>"
50
 
51
+
52
  # ๐Ÿ” Call Mistral using HF Inference Endpoint
53
  def call_mistral(prompt: str) -> Optional[str]:
54
  headers = {
 
87
  for doc in docs[:5]:
88
  prompt = build_prompt(doc, topic)
89
  print("\n๐Ÿ“ค Prompt sent to Mistral:\n", prompt[:300], "...\n")
90
+ summary_block = call_mistral(prompt)
91
+
92
+ if summary_block:
93
+ # Split by lines that start with "- " or "โ€“ " (dash or en dash)
94
+ for line in summary_block.splitlines():
95
+ line = line.strip()
96
+ if line.startswith("-") or line.startswith("โ€“"):
97
+ clean_summary = line.lstrip("-โ€“").strip()
98
+ if clean_summary:
99
+ feed.append({
100
+ "summary": clean_summary,
101
+ "image_url": "https://source.unsplash.com/800x600/?news",
102
+ "article_link": "https://google.com/search?q=" + topic.replace(" ", "+")
103
+ })
104
+
105
  return feed
106
 
107
+
108
  # โšก Generate and cache daily feed
109
  def generate_and_cache_daily_feed(documents: List[Document]):
110
  index = VectorStoreIndex.from_documents(documents)