ragV98 commited on
Commit
3008b61
Β·
1 Parent(s): 8b6cb43
components/LLMs/LLama3.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from typing import Optional
4
+
5
+ # πŸ” Environment Variables
6
+ LLAMA3_URL = "https://c5dk65n3sd14gjo1.us-east-1.aws.endpoints.huggingface.cloud"
7
+ HF_TOKEN = os.environ.get("HF_TOKEN")
8
+
9
+ # πŸ“œ Headers
10
+ HEADERS = {
11
+ "Authorization": f"Bearer {HF_TOKEN}",
12
+ "Content-Type": "application/json"
13
+ }
14
+
15
+ # 🧠 Prompt builder and caller for LLaMA 3 8B (QCA)
16
+ def call_llama3_8b(base_prompt: str, tail_prompt: str) -> Optional[str]:
17
+ prompt = f"<s>[INST]{base_prompt}\n\n{tail_prompt}[/INST]</s>"
18
+
19
+ try:
20
+ response = requests.post(
21
+ LLAMA3_URL,
22
+ headers=HEADERS,
23
+ json={"inputs": prompt},
24
+ timeout=60
25
+ )
26
+ response.raise_for_status()
27
+ data = response.json()
28
+
29
+ # Parse generated output
30
+ if isinstance(data, list) and data:
31
+ raw_output = data[0].get("generated_text", "")
32
+ elif isinstance(data, dict):
33
+ raw_output = data.get("generated_text", "")
34
+ else:
35
+ return None
36
+
37
+ if "[/INST]</s>" in raw_output:
38
+ return raw_output.split("[/INST]</s>")[-1].strip()
39
+ return raw_output.strip()
40
+
41
+ except Exception as e:
42
+ print(f"⚠️ LLaMA 3.1 8B API call failed: {e}")
43
+ return None
components/generators/daily_feed.py CHANGED
@@ -11,6 +11,7 @@ from llama_index.core.settings import Settings
11
  from components.LLMs.Mistral import call_mistral
12
  from components.LLMs.TinyLLama import call_tinyllama
13
  from components.LLMs.Bart import call_bart_summarizer
 
14
 
15
  # βœ… Disable implicit LLM usage
16
  Settings.llm = None
@@ -50,7 +51,7 @@ def summarize_topic(docs: List[str], topic: str) -> List[Dict]:
50
  for doc in docs[:5]:
51
  tail_prompt = f"Topic: {topic}\n\n{doc.strip()}"
52
  print(f"\nπŸ“€ Prompt tail for Mistral:\n{tail_prompt[:300]}...\n")
53
- summary_block = call_bart_summarizer(base_prompt=BASE_PROMPT, tail_prompt=tail_prompt)
54
 
55
  if summary_block:
56
  for line in summary_block.splitlines():
 
11
  from components.LLMs.Mistral import call_mistral
12
  from components.LLMs.TinyLLama import call_tinyllama
13
  from components.LLMs.Bart import call_bart_summarizer
14
+ from components.LLMs.LLama3 import call_llama3_8b
15
 
16
  # βœ… Disable implicit LLM usage
17
  Settings.llm = None
 
51
  for doc in docs[:5]:
52
  tail_prompt = f"Topic: {topic}\n\n{doc.strip()}"
53
  print(f"\nπŸ“€ Prompt tail for Mistral:\n{tail_prompt[:300]}...\n")
54
+ summary_block = call_llama3_8b(base_prompt=BASE_PROMPT, tail_prompt=tail_prompt)
55
 
56
  if summary_block:
57
  for line in summary_block.splitlines():