Artsem Radzevich commited on
Commit
f68897e
·
1 Parent(s): 291fc54

Added additional tools and moved to gemini.

Browse files
Files changed (1) hide show
  1. agent_config.py +40 -6
agent_config.py CHANGED
@@ -1,8 +1,34 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
2
  from tools.wiki_tool import WikiTool
3
  from tools.excel_analysis_tool import ExcelAnalysisTool
4
  import os
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  def create_agent():
7
  """
8
  Creates and configures the CodeAgent with the necessary model and tools.
@@ -16,17 +42,25 @@ def create_agent():
16
  raise RuntimeError("Missing Hugging Face API key. Set HF_API_KEY environment variable.")
17
 
18
  # Initialize the LLM model
19
- model = HfApiModel(token=token, model_id="gpt-3.5-turbo", provider="openai")
 
 
 
 
 
 
20
 
21
  # Initialize tools
22
- wiki_tool = WikiTool() # Custom Wikipedia wrapper
23
- web_search_tool = DuckDuckGoSearchTool() # Built-in smolagents web search tool
24
- excel_analysis_tool = ExcelAnalysisTool() # Custom Excel processing tool
 
 
25
 
26
  # Create and return the agent
27
  agent = CodeAgent(
28
  model=model,
29
- tools=[wiki_tool, web_search_tool, excel_analysis_tool],
30
  max_steps=8,
31
  verbosity_level=2
32
  )
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, VisitWebpageTool, PythonInterpreterTool, LiteLLMModel, tool
2
  from tools.wiki_tool import WikiTool
3
  from tools.excel_analysis_tool import ExcelAnalysisTool
4
  import os
5
 
6
+ @tool
7
+ def check_answer(answer: str) -> str:
8
+ """
9
+ Reviews the answer to check that it meets the requirements specified by the user and modifies it if necessary.
10
+ Args:
11
+ answer (str): The answer fo the Agent.
12
+ Returns:
13
+ str: The final answer.
14
+ """
15
+ return answer
16
+
17
+ @tool
18
+ def reverse_sentence_tool(reverse_sentence: str) -> str:
19
+ """
20
+ This tool receives a sentence where both the word order and the characters in each word are reversed.
21
+ It returns the sentence with words and order corrected.
22
+ Args:
23
+ reverse_sentence: A sentence with reversed words and reversed word order.
24
+ Returns:
25
+ A sentence in natural reading order.
26
+ """
27
+ inverted_words = reverse_sentence.split(" ")[::-1]
28
+ correct_words = [word[::-1] for word in inverted_words]
29
+
30
+ return " ".join(correct_words)
31
+
32
  def create_agent():
33
  """
34
  Creates and configures the CodeAgent with the necessary model and tools.
 
42
  raise RuntimeError("Missing Hugging Face API key. Set HF_API_KEY environment variable.")
43
 
44
  # Initialize the LLM model
45
+ # model = HfApiModel(token=token, model_id="gpt-3.5-turbo", provider="openai")
46
+
47
+ model = LiteLLMModel(
48
+ model_id="gemini/gemini-2.0-flash",
49
+ api_base="https://generativelanguage.googleapis.com/v1beta/models",
50
+ api_key=os.getenv("GEMINI_API_KEY")
51
+ )
52
 
53
  # Initialize tools
54
+ wiki_tool = WikiTool()
55
+ web_search_tool = DuckDuckGoSearchTool()
56
+ excel_analysis_tool = ExcelAnalysisTool()
57
+ visitWebpageTool = VisitWebpageTool()
58
+ python_interpreter_tool = PythonInterpreterTool()
59
 
60
  # Create and return the agent
61
  agent = CodeAgent(
62
  model=model,
63
+ tools=[wiki_tool, web_search_tool, excel_analysis_tool, visitWebpageTool, python_interpreter_tool, check_answer, reverse_sentence_tool],
64
  max_steps=8,
65
  verbosity_level=2
66
  )