File size: 2,657 Bytes
1999467
 
 
 
 
 
 
 
 
 
237f4e6
2638a6d
efbf494
2638a6d
4337336
752c309
0496865
 
3f1dcb6
2638a6d
55c1c64
 
fdcacb0
55c1c64
 
 
 
 
c551026
9d9535b
9d83242
2638a6d
 
 
 
4ca3e5b
3f1dcb6
55c1c64
4ca3e5b
4611b7a
a0cc714
2638a6d
9572d52
2638a6d
9d9535b
7c09eaf
 
9d9535b
 
 
 
 
 
 
 
2638a6d
9d9535b
fdcacb0
 
9d9535b
0f5b0a9
a407aaf
 
 
 
 
 
 
 
 
 
 
 
 
fdcacb0
 
 
 
a407aaf
9d9535b
 
 
 
9d83242
9d9535b
 
 
 
4337336
f280b77
7c09eaf
4337336
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from smolagents import (
    CodeAgent, 
    InferenceClientModel, 
    OpenAIServerModel, 
    VisitWebpageTool, 
    WebSearchTool, 
    WikipediaSearchTool, 
    PythonInterpreterTool,
    FinalAnswerTool
)
import os
from vision_tool import image_reasoning_tool

#token=os.getenv("HF_API_TOKEN")

OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
if not OPENROUTER_API_KEY:
    raise EnvironmentError("OPENROUTER_API_KEY environment variable not set")

common = dict(
    api_base="https://openrouter.ai/api/v1",
    api_key=OPENROUTER_API_KEY,
    #extra_body={"usage": {"include": True}}
)

#common = dict(
    #api_base = "https://generativelanguage.googleapis.com/v1beta/openai/",
    #api_key = os.getenv("GEMINI_API_KEY"),
#)
class GaiaAgent:
    def __init__(self):
        #import os
        #token = os.getenv("HF_API_TOKEN")
        #print("DEBUG: HF_API_TOKEN is", token[:6]+ "...")
        self.model = OpenAIServerModel(
            #max_tokens = 8096,
            temperature = 0.5,
            #model_id = "gemini-2.0-flash", 
            #model_id = 'qwen/qwen-2.5-coder-32b-instruct:free',
            model_id = "deepseek/deepseek-chat-v3-0324:free",
            #custom_role_conversions=None,      
            #provider="hf-inference",
            #token=token,
            **common
        )

#Creating the agent
        self.agent = CodeAgent(
            model=self.model,
            tools=[
                VisitWebpageTool(),
                WebSearchTool(),
                WikipediaSearchTool(),
                PythonInterpreterTool(),
                FinalAnswerTool(),
                image_reasoning_tool,
            ], 
            max_steps=6,
            verbosity_level = 1,        #or other parameter
            grammar = None,             
            planning_interval=3,
            additional_authorized_imports=[
                "markdownify",
                "json",
                "requests",
                "urllib.request",
                "urllib.parse",
                "wikipedia-api",
                "numpy",
                "math",
                "pytesseract",
                "PIL",
                "chess",
                "pandas",
                "os",
                "bs4",
                "openpyxl",
                "lxml"
            ]
            #name="web_agent",            
            #description="Brows the web to find information",      
            #additional_autorized_imports = ["pandas"],
        )
    def __call__(self, question: str) -> str:
        try:
            return self.agent.run(question)
        except Exception as e:
            return f"ERROR: {e}"