File size: 2,678 Bytes
8792035
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

#
#  GAIA's team suggested system prompt:
#  You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL 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), and write the digits in plain text unless specified otherwise. 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.
#

import sys
import time

# https://github.com/huggingface/smolagents/issues/1134
def delay_execution(pagent, **kwargs) -> bool:
    """
    Delays the execution for 10 seconds.
    """
    time.sleep(10)
    return True

STEP_CALLBACKS = [delay_execution]

from smolagents import OpenAIServerModel
from smolagents.agents import ToolCallingAgent

from src.toolkit import Toolkit

class MyAgent:

    def __init__(self, api_key):
        tk = Toolkit()
        toolkit = tk.get()
        # model = OpenAIServerModel( model_id="gemma-3-12b-it", api_base="http://127.0.0.1:1234/v1/", api_key="nono")
        model = OpenAIServerModel( model_id="gpt-4.1-mini", api_key=api_key)
        self.agent = ToolCallingAgent( tools=toolkit, model=model, planning_interval=3, step_callbacks=STEP_CALLBACKS)

    def answer(self, question, file=None):

        prompt = f"""You are a general AI assistant. 
        I will ask you a question. Report your thoughts, 
        and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. 
        YOUR FINAL ANSWER should be a number in numeric form 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), and write the digits in plain text unless specified otherwise. 
        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.
        Question: {question}"""

        return self.agent.run(prompt)
    
if __name__ == "__main__":

    argv = sys.argv
    if len(argv) < 2:
        print("Ask me something :)")
        exit(0)

    a = MyAgent().answer(argv[1])
    print(a)