File size: 2,295 Bytes
b8fd611
 
3edb388
e1064c3
b8fd611
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3edb388
 
 
b8fd611
e1064c3
 
 
 
 
 
1a6dacb
 
 
3edb388
 
 
 
e1064c3
 
f77a3e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1064c3
 
 
 
 
 
 
 
 
b8fd611
 
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
from smolagents import CodeAgent,  LiteLLMModel
import os
from cloudpathlib import AnyPath
from google.genai import types

from tools import initialize_all_available_tools


class MyAgent:
    def __init__(self, verbosity_level=0):
        model = LiteLLMModel(
            model_id="gemini/gemini-2.0-flash-lite",
            api_key=os.environ.get('GOOGLE_API_KEY')
        )
        tools = initialize_all_available_tools()

        self.agent = CodeAgent(
            tools=tools, 
            model=model, 
            max_steps=10,
            verbosity_level=verbosity_level
            )
        
        with AnyPath("gaia_prompt.txt").open("r", encoding='utf-8') as f:
            self.gaia_prompt = f.read()

    def get_answer(self, question, additional_data: dict | None = None):

        prompt = self.make_prompt(question)
        additional_args = self.make_additional_args(additional_data)

        answer = self.agent.run(prompt, additional_args=additional_args)

        answer = str(answer)

        fa_tmlp = "FINAL ANSWER:"
        if answer.startswith(fa_tmlp):
            answer = answer[len(fa_tmlp):]
        return answer.strip() 
    
    def make_prompt(self, question):

        custom_prompt = """ 
        I will ask you a question.  
        Your answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 
        If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
        If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities).
        If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.

        Examples:
        Q: What is the capital of France?
        A: Paris

        Q: What is 2+2 equal to?
        A: 4
        """

        return custom_prompt + '\n' + question
    
    def make_additional_args(self, additional_data: dict | None = None):
        if additional_data is None:
            return None
        
        return {"additional_file": types.Part.from_bytes(
            data=additional_data['content'],
            mime_type=additional_data['Content-Type'],
        )}