ekkasilina commited on
Commit
7e2c9ef
·
1 Parent(s): 007e18f

added reverse tools

Browse files
Files changed (3) hide show
  1. app.py +55 -18
  2. requirements.txt +2 -1
  3. tools.py +1 -0
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, tool
7
  from smolagents import OpenAIServerModel
8
  from tools import analyze_image, get_youtube_transcript, reverse_text
9
 
@@ -23,6 +23,41 @@ class BasicAgent:
23
  print(f"Agent returning fixed answer: {fixed_answer}")
24
  return fixed_answer
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  def run_and_submit_all( profile: gr.OAuthProfile | None):
28
  """
@@ -46,22 +81,24 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
46
  # 1. Instantiate Agent ( modify this part to create your agent)
47
  try:
48
  # agent = BasicAgent()
49
- openai_41mini_model = OpenAIServerModel(
50
- model_id="gpt-4.1-mini",
51
- api_base="https://api.openai.com/v1",
52
- api_key=os.environ["OPENAI_API_KEY"],
53
- )
54
- search_tool = DuckDuckGoSearchTool()
55
- my_small_agent = CodeAgent(
56
- model=openai_41mini_model,
57
- tools=[search_tool, analyze_image, get_youtube_transcript, reverse_text],
58
- name="web_agent",
59
- description="Use search engine to find webpages related to a subject and get the page content",
60
- #additional_authorized_imports=["pandas", "numpy","bs4"],
61
- verbosity_level=1,
62
- max_steps=7,
63
- )
64
-
 
 
65
  except Exception as e:
66
  print(f"Error instantiating agent: {e}")
67
  return f"Error initializing agent: {e}", None
@@ -102,7 +139,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
102
  continue
103
  try:
104
  #submitted_answer = agent(question_text)
105
- submitted_answer = my_small_agent.run(question_text)
106
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
107
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
108
  except Exception as e:
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, tool, ToolCallingAgent, MultiAgent
7
  from smolagents import OpenAIServerModel
8
  from tools import analyze_image, get_youtube_transcript, reverse_text
9
 
 
23
  print(f"Agent returning fixed answer: {fixed_answer}")
24
  return fixed_answer
25
 
26
+ openai_41mini_model = OpenAIServerModel(
27
+ model_id="gpt-4.1-mini",
28
+ api_base="https://api.openai.com/v1",
29
+ api_key=os.environ["OPENAI_API_KEY"],
30
+ )
31
+ search_tool = DuckDuckGoSearchTool()
32
+
33
+ analyst = CodeAgent(
34
+ model=openai_41mini_model,
35
+ tools=[reverse_text],
36
+ add_base_tools=False,
37
+ system_prompt=(
38
+ "You are the Analyst, skilled at decoding mysterious or reversed text. "
39
+ "When given a message, use your tools to reveal its correct form."
40
+ )
41
+ )
42
+ historian = ToolCallingAgent(
43
+ model=openai_41mini_model,
44
+ add_base_tools=False,
45
+ system_prompt=(
46
+ "You are the Historian. If a message seems written backward, consult the Analyst to decode it. "
47
+ "Otherwise, answer directly in clear language."
48
+ )
49
+ )
50
+
51
+ universal_agent = CodeAgent(
52
+ model=openai_41mini_model,
53
+ tools=[search_tool, analyze_image, get_youtube_transcript],
54
+ name="web_agent",
55
+ description="Use search engine to find webpages related to a subject and get the page content",
56
+ additional_authorized_imports=["pandas", "numpy", "bs4"],
57
+ verbosity_level=1,
58
+ max_steps=7,
59
+ )
60
+
61
 
62
  def run_and_submit_all( profile: gr.OAuthProfile | None):
63
  """
 
81
  # 1. Instantiate Agent ( modify this part to create your agent)
82
  try:
83
  # agent = BasicAgent()
84
+ # openai_41mini_model = OpenAIServerModel(
85
+ # model_id="gpt-4.1-mini",
86
+ # api_base="https://api.openai.com/v1",
87
+ # api_key=os.environ["OPENAI_API_KEY"],
88
+ # )
89
+ # search_tool = DuckDuckGoSearchTool()
90
+ # my_small_agent = CodeAgent(
91
+ # model=openai_41mini_model,
92
+ # tools=[search_tool, analyze_image, get_youtube_transcript, reverse_text],
93
+ # name="web_agent",
94
+ # description="Use search engine to find webpages related to a subject and get the page content",
95
+ # #additional_authorized_imports=["pandas", "numpy","bs4"],
96
+ # verbosity_level=1,
97
+ # max_steps=7,
98
+ # )
99
+
100
+ team = MultiAgent([historian, analyst, universal_agent])
101
+
102
  except Exception as e:
103
  print(f"Error instantiating agent: {e}")
104
  return f"Error initializing agent: {e}", None
 
139
  continue
140
  try:
141
  #submitted_answer = agent(question_text)
142
+ submitted_answer = team.run(question_text)
143
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
144
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
145
  except Exception as e:
requirements.txt CHANGED
@@ -3,4 +3,5 @@ requests
3
  smolagents
4
  ddgs
5
  openai
6
- youtube_transcript_api
 
 
3
  smolagents
4
  ddgs
5
  openai
6
+ youtube_transcript_api
7
+ beautifulsoup4
tools.py CHANGED
@@ -57,3 +57,4 @@ def reverse_text(question: str) -> str:
57
  reversed_candidate = question[::-1]
58
  return reversed_candidate
59
  return "Text seems normal."
 
 
57
  reversed_candidate = question[::-1]
58
  return reversed_candidate
59
  return "Text seems normal."
60
+