File size: 2,316 Bytes
331db0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# from google import genai
# from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
import os
from dotenv import load_dotenv
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, VisitWebpageTool, FinalAnswerTool
from tools import visitWikipedia, visitWikipediaTable
import time

load_dotenv()
google = os.getenv("GOOGLE")

# client = genai.Client(api_key=google)
# google_search_tool = Tool(
#     google_search = GoogleSearch()
# )
# response = client.models.generate_content(
#     model="gemini-2.0-flash",
#     contents = prompt,
#     config=GenerateContentConfig(
#         tools=[google_search_tool],
#         response_modalities=["TEXT"],
#     )
# )
# print(response.text)

model = LiteLLMModel(
    model_id="gemini/gemini-2.0-flash",
    api_key=google,
    max_tokens=1000,
    temperature=0.0,
)
tools = [FinalAnswerTool(), DuckDuckGoSearchTool(), VisitWebpageTool(), visitWikipedia, visitWikipediaTable]
agent = CodeAgent(
    tools=tools, 
    model=model,
    additional_authorized_imports=["math", "datetime", "re", "json", "pandas", "numpy"],
    max_steps=15,
    )

prompt = """
Do not assume your code is correct. Always check your code and the output of your code.
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the FinalAnswerTool(). 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.
Question:
"""

def run(question):
    try: 
        return agent.run(task=prompt+"\n"+question)
    except Exception as e:
        time.sleep(60)
        return agent.run(task=prompt+"\n"+question)

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 = run(question)
# print(answer)