File size: 1,607 Bytes
8df193a
146a978
b63dea2
 
 
 
 
 
 
90e87ac
f600343
c6abe85
76a07e7
dc9ea5d
 
 
 
e35fcb9
dc9ea5d
ce19e01
b63dea2
e35fcb9
 
 
90e87ac
 
e35fcb9
 
90e87ac
b63dea2
06a45b9
 
8b5c1fe
7988b10
a64b881
8b5c1fe
8df193a
 
5d86374
90e87ac
3f4b538
 
 
 
 
76a07e7
8df193a
 
e891bbf
18e5e9a
8df193a
 
1c61347
8df193a
8b5c1fe
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
from openai import OpenAI

from smolagents import (
    CodeAgent, 
    OpenAIServerModel, 
    DuckDuckGoSearchTool, 
    WikipediaSearchTool
)

MODEL_ID_1 = "gpt-4o"
MODEL_ID_2 = "o4-mini"

def run_agent(level, question, file_name):
    if level == 1:
        max_steps = 5
    elif level == 2:
        max_steps = 10
    elif level == 3:
        max_steps = 20
   
    agent = CodeAgent(
            add_base_tools = True,
            additional_authorized_imports = ["pandas", "numpy"],
            max_steps = max_steps,
            model = OpenAIServerModel(model_id = MODEL_ID_1),
            #planning_interval=3,
            tools = [DuckDuckGoSearchTool(), 
                     WikipediaSearchTool()],
            #verbosity_level = 2
        )

    answer = agent.run(question)

    return get_final_answer(question, answer)

def get_final_answer(question, answer):
    client = OpenAI()

    prompt_template = """
You are a GAIA benchmark assistant, who is given a question and an answer. Read the question carefully. You must only give the final answer requested. Do not include explanations, steps, reasoning, or additional text. Be direct and specific.
**Question:** """ + str(question) + """
**Answer:** """ + str(answer) + """
**Example:** If asked "What is the capital of France?", respond with "Paris".
**Final answer:**:

"""

    completion = client.chat.completions.create(
        messages = [{"role": "user", "content": [{"type": "text", "text": prompt_template}]}],
        model = MODEL_ID_2
    )

    final_answer = completion.choices[0].message.content

    return final_answer