Aishwaryas16 commited on
Commit
762230a
·
verified ·
1 Parent(s): d265a3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -16,29 +16,38 @@ from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, ApiModel
16
 
17
  from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, ApiModel
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  class BasicAgent:
20
  def __init__(self):
21
- print("🔥 Smart Agent initialized")
22
 
23
- # FIXED MODEL (IMPORTANT)
24
- self.model = ApiModel(
25
- model_id="mistralai/Mistral-7B-Instruct-v0.2",
26
- provider="hf" # ⭐ THIS LINE FIXES YOUR ERROR
27
- )
28
 
29
  self.agent = ToolCallingAgent(
30
  tools=[DuckDuckGoSearchTool()],
31
  model=self.model,
32
- max_steps=10,
33
  name="gaia_agent",
34
  description="Smart QA agent"
35
  )
36
 
37
- self.agent.system_prompt = """
38
- Return ONLY the final answer.
39
- No explanation.
40
- """
41
-
42
  def clean(self, text):
43
  text = str(text).strip()
44
  text = text.replace("Final Answer:", "")
 
16
 
17
  from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, ApiModel
18
 
19
+ from smolagents import ToolCallingAgent, DuckDuckGoSearchTool
20
+ import requests
21
+ import os
22
+
23
+ class HFModel:
24
+ def __init__(self):
25
+ self.API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
26
+ self.headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
27
+
28
+ def generate(self, prompt):
29
+ response = requests.post(
30
+ self.API_URL,
31
+ headers=self.headers,
32
+ json={"inputs": prompt, "parameters": {"max_new_tokens": 100}}
33
+ )
34
+ return response.json()[0]["generated_text"]
35
+
36
+
37
  class BasicAgent:
38
  def __init__(self):
39
+ print("🔥 Custom HF Agent initialized")
40
 
41
+ self.model = HFModel()
 
 
 
 
42
 
43
  self.agent = ToolCallingAgent(
44
  tools=[DuckDuckGoSearchTool()],
45
  model=self.model,
46
+ max_steps=8,
47
  name="gaia_agent",
48
  description="Smart QA agent"
49
  )
50
 
 
 
 
 
 
51
  def clean(self, text):
52
  text = str(text).strip()
53
  text = text.replace("Final Answer:", "")