File size: 1,531 Bytes
4d4b0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6942270
4d4b0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import os
from dotenv import load_dotenv
from smolagents import CodeAgent, WikipediaSearchTool, VisitWebpageTool, DuckDuckGoSearchTool, InferenceClientModel

load_dotenv()

print(os.environ)

class TheAgent:
    def __init__(self):
      headers = {
          "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
          "Accept-Language": "en-US,en;q=0.9,en;q=0.8"
      }

      search_tool = DuckDuckGoSearchTool(rate_limit = 5, headers=headers)
      wiki_tool = WikipediaSearchTool()
      page_tool = VisitWebpageTool()

      model_id = "Qwen/Qwen3-235B-A22B-Instruct-2507"
      # model_id = "Qwen/Qwen3-1.7B"

      self.agent = CodeAgent(
          tools=[wiki_tool, page_tool, search_tool],
          model=InferenceClientModel(model_id=model_id),
      )

      print("BasicAgent initialized.")

    def __call__(self, question: str):
      try:
          result = self.agent.run(question)
          return str(result)
      except requests.exceptions.HTTPError as e:
          print(f"Error: {e.response.text}")

if __name__ == "__main__":
    agent = TheAgent()
    question = "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?"
    question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
    answer = agent(question)
    print(f"Answer: {answer}")