prompt revision 6
Browse files
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 โ
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 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)
|