ragV98 commited on
Commit
71257bd
·
1 Parent(s): a62e0f6

changing prompt structure

Browse files
Files changed (1) hide show
  1. components/generators/daily_feed.py +14 -5
components/generators/daily_feed.py CHANGED
@@ -36,7 +36,7 @@ def build_prompt(content: str, topic: str) -> str:
36
 
37
  # 🧠 Send prompt to Mistral
38
  def call_mistral(prompt: str) -> str:
39
- if not prompt or len(prompt.strip()) < 50:
40
  print(f"⚠️ Skipping empty or invalid prompt:\n{prompt}\n")
41
  return None
42
 
@@ -45,19 +45,28 @@ def call_mistral(prompt: str) -> str:
45
  "Content-Type": "application/json"
46
  }
47
  payload = {
48
- "inputs": [{"role": "user", "content": prompt}]
49
  }
50
 
51
- print(f"\n📤 Prompt sent to Mistral:\n{prompt[:300]}...\n") # show a snippet for debugging
52
-
53
  try:
54
  response = requests.post(MISTRAL_URL, headers=headers, json=payload, timeout=20)
55
  response.raise_for_status()
56
- return response.json()["outputs"][0]["content"].strip()
 
 
 
 
 
 
 
 
 
 
57
  except Exception as e:
58
  print(f"⚠️ Mistral error: {e}")
59
  return None
60
 
 
61
  # ✂️ Generate summaries per topic
62
  def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
63
  feed = []
 
36
 
37
  # 🧠 Send prompt to Mistral
38
  def call_mistral(prompt: str) -> str:
39
+ if not prompt or len(prompt.strip()) < 10:
40
  print(f"⚠️ Skipping empty or invalid prompt:\n{prompt}\n")
41
  return None
42
 
 
45
  "Content-Type": "application/json"
46
  }
47
  payload = {
48
+ "inputs": prompt
49
  }
50
 
 
 
51
  try:
52
  response = requests.post(MISTRAL_URL, headers=headers, json=payload, timeout=20)
53
  response.raise_for_status()
54
+ result = response.json()
55
+ # HF sometimes returns raw string, sometimes list/dict
56
+ if isinstance(result, dict) and "generated_text" in result:
57
+ return result["generated_text"].strip()
58
+ elif isinstance(result, list) and "generated_text" in result[0]:
59
+ return result[0]["generated_text"].strip()
60
+ elif "outputs" in result:
61
+ return result["outputs"][0]["content"].strip()
62
+ else:
63
+ print(f"⚠️ Unexpected response format: {result}")
64
+ return None
65
  except Exception as e:
66
  print(f"⚠️ Mistral error: {e}")
67
  return None
68
 
69
+
70
  # ✂️ Generate summaries per topic
71
  def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
72
  feed = []