samsonDzealot commited on
Commit
8a4745b
·
verified ·
1 Parent(s): 75ae6d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -35
app.py CHANGED
@@ -46,42 +46,40 @@ class BasicAgent:
46
  print(f"Agent tools initialized: {list(self.tools.keys())}")
47
 
48
  def _call_llm(self, conversation_history: list) -> str:
49
- print(f"Calling LLM. Conversation history length: {len(conversation_history)}")
50
-
51
- # Hugging Face headers (simpler)
52
- headers = {
53
- "Authorization": f"Bearer {self.api_key}", # should be your HF token
54
- "Content-Type": "application/json"
55
- }
56
-
57
- # Format conversation into a single prompt string
58
- # You can improve this formatting later if needed
59
- prompt = ""
60
- for turn in conversation_history:
61
- role = turn.get("role", "user").capitalize()
62
- content = turn.get("content", "")
63
- prompt += f"{role}: {content}\n"
64
- prompt += "Assistant:"
65
-
66
- # Payload for Hugging Face
67
- payload = {
68
- "inputs": prompt,
69
- "parameters": {
70
- "temperature": 0.7,
71
- "max_new_tokens": 512
72
  }
73
- }
74
-
75
- url = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-V3"
76
- response = requests.post(url, headers=headers, json=payload)
77
-
78
- try:
79
- return response.json()[0]["generated_text"].split("Assistant:")[-1].strip()
80
- except Exception:
81
- return f"Error: {response.text}"
82
-
83
-
84
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  def __call__(self, question_data: dict) -> str:
86
  task_id = question_data.get("task_id")
87
  question_text = question_data.get("question")
 
46
  print(f"Agent tools initialized: {list(self.tools.keys())}")
47
 
48
  def _call_llm(self, conversation_history: list) -> str:
49
+ print(f"Calling LLM. Conversation history length: {len(conversation_history)}")
50
+
51
+ # Hugging Face headers (simpler)
52
+ headers = {
53
+ "Authorization": f"Bearer {self.api_key}", # should be your HF token
54
+ "Content-Type": "application/json"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
+
57
+ # Format conversation into a single prompt string
58
+ # You can improve this formatting later if needed
59
+ prompt = ""
60
+ for turn in conversation_history:
61
+ role = turn.get("role", "user").capitalize()
62
+ content = turn.get("content", "")
63
+ prompt += f"{role}: {content}\n"
64
+ prompt += "Assistant:"
65
+
66
+ # Payload for Hugging Face
67
+ payload = {
68
+ "inputs": prompt,
69
+ "parameters": {
70
+ "temperature": 0.7,
71
+ "max_new_tokens": 512
72
+ }
73
+ }
74
+
75
+ url = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-V3"
76
+ response = requests.post(url, headers=headers, json=payload)
77
+
78
+ try:
79
+ return response.json()[0]["generated_text"].split("Assistant:")[-1].strip()
80
+ except Exception:
81
+ return f"Error: {response.text}"
82
+
83
  def __call__(self, question_data: dict) -> str:
84
  task_id = question_data.get("task_id")
85
  question_text = question_data.get("question")