should work this time
Browse files
components/generators/daily_feed.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import sys
|
3 |
import json
|
4 |
import requests
|
|
|
5 |
|
6 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
7 |
|
@@ -35,36 +36,43 @@ def build_prompt(content: str, topic: str) -> str:
|
|
35 |
)
|
36 |
|
37 |
# 🧠 Send prompt to Mistral
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
47 |
payload = {
|
48 |
-
"inputs": prompt
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
|
51 |
try:
|
52 |
-
response = requests.post(MISTRAL_URL, headers=
|
53 |
response.raise_for_status()
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
65 |
except Exception as e:
|
66 |
-
print(
|
67 |
-
|
|
|
68 |
|
69 |
|
70 |
# ✂️ Generate summaries per topic
|
|
|
2 |
import sys
|
3 |
import json
|
4 |
import requests
|
5 |
+
from requests.exceptions import RequestException
|
6 |
|
7 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
8 |
|
|
|
36 |
)
|
37 |
|
38 |
# 🧠 Send prompt to Mistral
|
39 |
+
HEADERS = {
|
40 |
+
"Authorization": f"Bearer {HF_TOKEN}",
|
41 |
+
"Content-Type": "application/json"
|
42 |
+
}
|
43 |
+
|
44 |
+
def call_mistral(prompt: str, max_new_tokens: int = 128, temperature: float = 0.7) -> str:
|
45 |
+
"""
|
46 |
+
Call Hugging Face Inference Endpoint hosting Mistral-7B.
|
47 |
+
Returns the generated summary, or empty string on failure.
|
48 |
+
"""
|
49 |
payload = {
|
50 |
+
"inputs": prompt,
|
51 |
+
"parameters": {
|
52 |
+
"max_new_tokens": max_new_tokens,
|
53 |
+
"temperature": temperature
|
54 |
+
}
|
55 |
}
|
56 |
|
57 |
try:
|
58 |
+
response = requests.post(MISTRAL_URL, headers=HEADERS, json=payload, timeout=60)
|
59 |
response.raise_for_status()
|
60 |
+
data = response.json()
|
61 |
+
|
62 |
+
# Handle both list and dict output formats
|
63 |
+
if isinstance(data, list) and data:
|
64 |
+
return data[0].get("generated_text", "").strip()
|
65 |
+
if isinstance(data, dict) and "generated_text" in data:
|
66 |
+
return data["generated_text"].strip()
|
67 |
+
|
68 |
+
except RequestException as e:
|
69 |
+
print("❌ Mistral HF request failed:", str(e))
|
70 |
+
if e.response is not None:
|
71 |
+
print("↪️ Response:", e.response.text[:300])
|
72 |
except Exception as e:
|
73 |
+
print("❌ Unexpected error:", str(e))
|
74 |
+
|
75 |
+
return ""
|
76 |
|
77 |
|
78 |
# ✂️ Generate summaries per topic
|