|
|
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" |
|
|
|
|
|
|
|
|
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}") |
|
|
|