krzsam commited on
Commit
8b3139e
·
1 Parent(s): a516261

Add Excel and Python file loading tools with tests and dependencies

Browse files

- Added ExcelLoadTool to load and parse Excel files
- Added PythonLoadTool to load Python source code files
- Updated requirements.txt with necessary dependencies (pandas, openpyxl, etc.)
- Added test cases for the new tools in test_tools.py
- Updated prompt configurations in my_prompt_config.py

Files changed (8) hide show
  1. .gitignore +3 -0
  2. app.py +22 -27
  3. my_agent.py +41 -23
  4. my_prompt_config.py +127 -18
  5. my_tool_excel_load.py +50 -0
  6. my_tool_python_load.py +46 -0
  7. requirements.txt +6 -1
  8. test_tools.py +20 -1
.gitignore CHANGED
@@ -4,3 +4,6 @@
4
  /venv/
5
  /.idea/
6
  /questions/
 
 
 
 
4
  /venv/
5
  /.idea/
6
  /questions/
7
+ /train-data/
8
+ /saved_models/
9
+ /chess-pieces/
app.py CHANGED
@@ -10,28 +10,28 @@ from my_agent import MyAgent
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # testing --------------------------------------------
13
- testing_mode = True
14
  questions_to_run = [
15
- #"8e867cd7-cff9-4e6c-867a-ff5ddc2550be", # - 3, should be ok
16
- #"a1e91b78-d3d8-4675-bb8d-62741b4b68a6", # - video
17
- #"2d83110e-a098-4ebb-9987-066c06fa42d0", # OK
18
- #"cca530fc-4052-43b2-b130-b30968d8aa44", # OK
19
- "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8", # - FunkMonk, wrong answer https://en.wikipedia.org/wiki/Giganotosaurus
20
- #"6f37996b-2ac7-44b0-8e68-6d28256631b4", # -
21
- #"9d191bce-651d-4746-be2d-7ef8ecadb9c2", # -
22
- #"cabe07ed-9eca-40ea-8ead-410ef5e83f91", # -
23
- #"3cef3a44-215e-4aed-8e3b-b1e3f08063b7", # -
24
- #"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3", # -
25
- #"305ac316-eef6-4446-960a-92d80d542f82", # Hubert ?
26
- #"f918266a-b3e0-4914-865d-4faa564f1aef", # -
27
- #"3f57289b-8c60-48be-bd80-01f8099ca449", # 566 ?
28
- #"1f975693-876d-457b-a649-393859e79bf3", # -
29
- #"840bfca7-4f7b-481a-8794-c560c340185d", # 80NSSC20K0910 ?
30
- #"bda648d7-d618-4883-88f4-3466eabd860e", # Saint Petersburg ?
31
- #"cf106601-ab4f-4af9-b045-5295fe67b37d", # -
32
- #"a0c07678-e491-4bbc-8f0b-07405144218f", # -
33
- #"7bd855d8-463d-4ed5-93ca-5fe35145f733", # -
34
- #"5a0c1adf-205e-4841-a666-7c3ef95def9d", # Vladimir ?
35
  ]
36
  # testing --------------------------------------------
37
 
@@ -97,7 +97,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
97
  for item in questions_data:
98
  task_id = item.get("task_id")
99
  question_text = item.get("question")
100
- question_file_name = item.get("file_name")
101
 
102
  if not task_id or question_text is None:
103
  print(f"Skipping item with missing task_id or question: {item}")
@@ -108,11 +107,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
108
  continue
109
 
110
  try:
111
- #if question_file_name is not None:
112
- # ext = question_file_name[-4:]
113
- # if ext == ".png":
114
- # question_text = question_text + (f" Use one of available tools to load an image associated with "
115
- # f"task_id: '{task_id}'")
116
  question_text = question_text + f" task_id: '{task_id}'"
117
 
118
  submitted_answer = agent(question_text)
@@ -128,6 +122,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
128
 
129
  # 4. Prepare Submission
130
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
131
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
132
  print(status_update)
133
 
 
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # testing --------------------------------------------
13
+ testing_mode = False
14
  questions_to_run = [
15
+ #"8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
16
+ #"a1e91b78-d3d8-4675-bb8d-62741b4b68a6",
17
+ #"2d83110e-a098-4ebb-9987-066c06fa42d0",
18
+ #"cca530fc-4052-43b2-b130-b30968d8aa44",
19
+ #"4fc2f1ae-8625-45b5-ab34-ad4433bc21f8",
20
+ #"6f37996b-2ac7-44b0-8e68-6d28256631b4",
21
+ #"9d191bce-651d-4746-be2d-7ef8ecadb9c2",
22
+ #"cabe07ed-9eca-40ea-8ead-410ef5e83f91",
23
+ #"3cef3a44-215e-4aed-8e3b-b1e3f08063b7",
24
+ #"99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3",
25
+ #"305ac316-eef6-4446-960a-92d80d542f82",
26
+ #"f918266a-b3e0-4914-865d-4faa564f1aef",
27
+ #"3f57289b-8c60-48be-bd80-01f8099ca449",
28
+ #"1f975693-876d-457b-a649-393859e79bf3",
29
+ #"840bfca7-4f7b-481a-8794-c560c340185d",
30
+ #"bda648d7-d618-4883-88f4-3466eabd860e",
31
+ #"cf106601-ab4f-4af9-b045-5295fe67b37d",
32
+ #"a0c07678-e491-4bbc-8f0b-07405144218f",
33
+ #"7bd855d8-463d-4ed5-93ca-5fe35145f733",
34
+ #"5a0c1adf-205e-4841-a666-7c3ef95def9d",
35
  ]
36
  # testing --------------------------------------------
37
 
 
97
  for item in questions_data:
98
  task_id = item.get("task_id")
99
  question_text = item.get("question")
 
100
 
101
  if not task_id or question_text is None:
102
  print(f"Skipping item with missing task_id or question: {item}")
 
107
  continue
108
 
109
  try:
 
 
 
 
 
110
  question_text = question_text + f" task_id: '{task_id}'"
111
 
112
  submitted_answer = agent(question_text)
 
122
 
123
  # 4. Prepare Submission
124
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
125
+ print(f"Submission data is:\n{submission_data}")
126
  status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
127
  print(status_update)
128
 
my_agent.py CHANGED
@@ -1,6 +1,14 @@
1
- from smolagents import CodeAgent, InferenceClientModel, WebSearchTool, FinalAnswerTool
2
- #from smolagents import ApiModel
3
- #from mistralai import Mistral
 
 
 
 
 
 
 
 
4
  import os
5
  # --------- my tools
6
  from my_tool_reverse_string import ReverseStringTool
@@ -15,6 +23,8 @@ from my_tool_wiki_featured_articles import MyWikiFeaturedArticles
15
  from my_tools_libretexts import MyLibreTextsBookshelvesTool, MyLibreTextsBooksTool
16
  from my_tools_libretexts import MyLibreTextsBookSectionsTool, MyLibreTextsBookSectionParagraphsTool
17
  from my_tools_libretexts import MyLibreTextsParagraphContentsTool
 
 
18
  from dotenv import load_dotenv
19
 
20
  # https://huggingface.co/docs/transformers/model_doc/mistral?usage=Pipeline
@@ -23,12 +33,17 @@ from dotenv import load_dotenv
23
  # --- Basic Agent Definition ---
24
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
25
  class MyAgent:
26
- #MODEL_REASONING = "Qwen/Qwen2.5-Coder-32B-Instruct"
27
- #MODEL_REASONING = "deepseek-ai/DeepSeek-R1"
28
- MODEL_REASONING = "Qwen/Qwen3-235B-A22B" # test more
29
- #MODEL_REASONING = "Qwen/Qwen3-235B-A22B-Thinking-2507"
30
- #MODEL_REASONING = "Qwen/Qwen3-235B-A22B-Thinking-2507-FP8"
31
- #MODEL_REASONING = "mistralai/Mixtral-8x22B-v0.1" # not available via HuggingFace
 
 
 
 
 
32
  chess_board_model_name = "my_chess_pieces_recognition.pth"
33
  chess_board_model_dir = "/mnt/c/Users/krzsa/IdeaProjects/Agents-Course-Assignment/saved_models"
34
 
@@ -39,17 +54,6 @@ class MyAgent:
39
  self.__create_agents__()
40
 
41
  def __create_agents__(self):
42
- # --- Mistral -----------------------------------------------------------------------------------
43
- # will need class implementation based on ApiModel
44
- # https://github.com/huggingface/smolagents/blob/main/src/smolagents/models.py
45
- # https://github.com/mistralai/client-python/tree/main/examples
46
- #self.mistral_client = Mistral(api_key=self.mistral_api_key)
47
- #self.model = ApiModel(
48
- # model_id="mistral-large-2411",
49
- # client=self.mistral_client
50
- #)
51
- # --- Mistral -----------------------------------------------------------------------------------
52
-
53
  # --- HF Inference ------------------------------------------------------------------------------
54
  self.model = InferenceClientModel(model_id=self.MODEL_REASONING)
55
  # --- HF Inference ------------------------------------------------------------------------------
@@ -65,8 +69,6 @@ class MyAgent:
65
  name="CourseAssistant",
66
  description="General AI Assistant",
67
  tools=[
68
- WebSearchTool(),
69
- # -------
70
  ImageLoadTool(),
71
  ReverseStringTool(),
72
  ChessBoard(self.chess_board_model_name, self.chess_board_model_dir),
@@ -80,6 +82,13 @@ class MyAgent:
80
  MyLibreTextsBookSectionsTool(),
81
  MyLibreTextsBookSectionParagraphsTool(),
82
  MyLibreTextsParagraphContentsTool(),
 
 
 
 
 
 
 
83
  # ---------
84
  FinalAnswerTool(),
85
  ],
@@ -88,6 +97,8 @@ class MyAgent:
88
  prompt_templates=MyPromptConfig.PROMPT_TEMPLATES,
89
  managed_agents=[],
90
  additional_authorized_imports=[
 
 
91
  "PIL",
92
  "chess",
93
  "matplotlib",
@@ -108,7 +119,14 @@ class MyAgent:
108
  "my_tool_wiki_table_filter",
109
  "my_tool_wiki_featured_articles",
110
  "my_tools_libretexts",
111
- "my_base_libretexts_api"
 
 
 
 
 
 
 
112
  ],
113
  )
114
  print(f"Main agent initialized: {self.reasoning_agent}")
 
1
+ from smolagents import (
2
+ CodeAgent,
3
+ InferenceClientModel,
4
+ PythonInterpreterTool, # python_interpreter
5
+ FinalAnswerTool, # final_answer
6
+ VisitWebpageTool, # visit_webpage
7
+ WikipediaSearchTool, # wikipedia_search
8
+ WebSearchTool, # web_search
9
+ PythonInterpreterTool, # python_interpreter
10
+ SpeechToTextTool,
11
+ )
12
  import os
13
  # --------- my tools
14
  from my_tool_reverse_string import ReverseStringTool
 
23
  from my_tools_libretexts import MyLibreTextsBookshelvesTool, MyLibreTextsBooksTool
24
  from my_tools_libretexts import MyLibreTextsBookSectionsTool, MyLibreTextsBookSectionParagraphsTool
25
  from my_tools_libretexts import MyLibreTextsParagraphContentsTool
26
+ from my_tool_excel_load import ExcelLoadTool
27
+ from my_tool_python_load import PythonLoadTool
28
  from dotenv import load_dotenv
29
 
30
  # https://huggingface.co/docs/transformers/model_doc/mistral?usage=Pipeline
 
33
  # --- Basic Agent Definition ---
34
  # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
35
  class MyAgent:
36
+ #MODEL_REASONING = "deepseek-ai/DeepSeek-V3.1" # better
37
+
38
+ # check again as there were problems with duck duck go
39
+ MODEL_REASONING = "deepseek-ai/DeepSeek-V3.1-Terminus" # much worse
40
+
41
+ #MODEL_REASONING = "openai/gpt-oss-120b" # not working at all
42
+
43
+ # check again as there were problems with duck duck go
44
+ # MODEL_REASONING = "Qwen/Qwen3-Coder-480B-A35B-Instruct" # worked rather quick
45
+ #MODEL_REASONING = "deepseek-ai/DeepSeek-R1-0528"
46
+
47
  chess_board_model_name = "my_chess_pieces_recognition.pth"
48
  chess_board_model_dir = "/mnt/c/Users/krzsa/IdeaProjects/Agents-Course-Assignment/saved_models"
49
 
 
54
  self.__create_agents__()
55
 
56
  def __create_agents__(self):
 
 
 
 
 
 
 
 
 
 
 
57
  # --- HF Inference ------------------------------------------------------------------------------
58
  self.model = InferenceClientModel(model_id=self.MODEL_REASONING)
59
  # --- HF Inference ------------------------------------------------------------------------------
 
69
  name="CourseAssistant",
70
  description="General AI Assistant",
71
  tools=[
 
 
72
  ImageLoadTool(),
73
  ReverseStringTool(),
74
  ChessBoard(self.chess_board_model_name, self.chess_board_model_dir),
 
82
  MyLibreTextsBookSectionsTool(),
83
  MyLibreTextsBookSectionParagraphsTool(),
84
  MyLibreTextsParagraphContentsTool(),
85
+ PythonInterpreterTool(),
86
+ VisitWebpageTool(),
87
+ WikipediaSearchTool(),
88
+ WebSearchTool(),
89
+ SpeechToTextTool(),
90
+ ExcelLoadTool(),
91
+ PythonLoadTool(),
92
  # ---------
93
  FinalAnswerTool(),
94
  ],
 
97
  prompt_templates=MyPromptConfig.PROMPT_TEMPLATES,
98
  managed_agents=[],
99
  additional_authorized_imports=[
100
+ "os",
101
+ "io"
102
  "PIL",
103
  "chess",
104
  "matplotlib",
 
119
  "my_tool_wiki_table_filter",
120
  "my_tool_wiki_featured_articles",
121
  "my_tools_libretexts",
122
+ "my_base_libretexts_api",
123
+ "my_tool_excel_load",
124
+ "my_tool_python_load",
125
+ "smolagents",
126
+ "transformers",
127
+ "pandas",
128
+ "openpyxl",
129
+ "markdownify"
130
  ],
131
  )
132
  print(f"Main agent initialized: {self.reasoning_agent}")
my_prompt_config.py CHANGED
@@ -11,13 +11,9 @@ class MyPromptConfig:
11
 
12
  Answer the following questions as best you can.
13
 
14
- Describe your initial plan as a set of bullet points.
15
- Each bullet point should describe in one sentence an action which is to be taken in this step.
16
  Do NOT provide hypothetical examples for the final answer.
17
 
18
  Use the tools provided, and only those which are necessary to answer the question.
19
- If you are going to use a tool, describe in detail how you are going
20
- to invoke the tool and explain parameters used to invoke the tool.
21
 
22
  The list of tools available is provided below. They allow to solve a variety of various questions asked.
23
  Decide and pick and use only tools which are necessary to answer the question asked.
@@ -37,27 +33,131 @@ class MyPromptConfig:
37
  * _my_tool_libretexts_book_sections : Get a list of sections in a book in LibreTexts materials
38
  * _my_tool_libretexts_book_section_paragraphs : Get a list of section paragraphs in a book in LibreTexts materials
39
  * _my_tool_libretexts_paragraph_contents : Get contents of a paragraph in a book in LibreTexts materials
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  If the question mentions image or other file, use one of provided tools to load it
42
  using task_id associated with the question.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  """,
44
  planning=PlanningPromptTemplate(
45
- initial_plan="""
46
-
47
- """,
48
- update_plan_pre_messages="""
49
-
50
- """,
51
- update_plan_post_messages="""
52
-
53
- """,
54
  ),
55
  managed_agent=ManagedAgentPromptTemplate(task="", report=""),
56
  final_answer=FinalAnswerPromptTemplate(
57
- pre_messages="",
58
- post_messages="""
59
- Report your answer using final_answer tool
60
-
61
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of
62
  numbers and/or strings.
63
  If you are asked for a number, don’t use comma to write your number neither use units such as $ or
@@ -66,7 +166,16 @@ class MyPromptConfig:
66
  and write the digits in plain text unless specified otherwise.
67
  If you are asked for a comma separated list, apply the above rules depending of whether the element
68
  to be put in the list is a number or a string
69
- """
 
 
 
 
 
 
 
 
 
70
  ),
71
  )
72
 
 
11
 
12
  Answer the following questions as best you can.
13
 
 
 
14
  Do NOT provide hypothetical examples for the final answer.
15
 
16
  Use the tools provided, and only those which are necessary to answer the question.
 
 
17
 
18
  The list of tools available is provided below. They allow to solve a variety of various questions asked.
19
  Decide and pick and use only tools which are necessary to answer the question asked.
 
33
  * _my_tool_libretexts_book_sections : Get a list of sections in a book in LibreTexts materials
34
  * _my_tool_libretexts_book_section_paragraphs : Get a list of section paragraphs in a book in LibreTexts materials
35
  * _my_tool_libretexts_paragraph_contents : Get contents of a paragraph in a book in LibreTexts materials
36
+ * _my_tool_excel_load : load Excel file for given task_id
37
+ * _my_tool_python_load : load Python file for given task_id
38
+ * python_interpreter : This is a tool that evaluates python code. It can be used to perform calculations.
39
+ * visit_webpage : Visits a webpage at the given url and reads its content as a markdown string. Use this to browse webpages.
40
+ * wikipedia_search : Search Wikipedia and return the summary or full text of the requested article, along with the page URL.
41
+ * web_search : Performs a web search for your query then returns a string of the top search results.
42
+
43
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of
44
+ numbers and/or strings.
45
+ If you are asked for a number, don’t use comma to write your number neither use units such as $ or
46
+ percent sign unless specified otherwise.
47
+ If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities),
48
+ and write the digits in plain text unless specified otherwise.
49
+ If you are asked for a comma separated list, apply the above rules depending of whether the element
50
+ to be put in the list is a number or a string
51
 
52
  If the question mentions image or other file, use one of provided tools to load it
53
  using task_id associated with the question.
54
+
55
+ Use the tools using the examples provided below.
56
+
57
+ <code>
58
+ loaded_image = _my_tool_image_load(task_id="dummy")
59
+ </code>
60
+
61
+ <code>
62
+ loaded_python_file = _my_tool_python_load(task_id="dummy")
63
+ </code>
64
+
65
+ <code>
66
+ contents = _my_tool_excel_load(task_id="dummy")
67
+ </code>
68
+
69
+ <code>
70
+ reversed_string = _my_tool_reverse_string(input_str="dummy")
71
+ </code>
72
+
73
+ <code>
74
+ chess_pieces = _my_tool_chess_board(img=loaded_image)
75
+ </code>
76
+
77
+ <code>
78
+ loaded_fen = _my_tool_fen(chest_pieces="dummy")
79
+ </code>
80
+
81
+ <code>
82
+ best_answer = _my_tool_chess_analysis(fen=loaded_fen, player_color="dummy")
83
+ </code>
84
+
85
+ <code>
86
+ section_contents = _my_tool_wiki_page_section(page_title='aaa', section_title='bbb', version='2022')
87
+ </code>
88
+
89
+ <code>
90
+ table_data = _my_tool_wiki_table_filter(section_content='aaa', sub_section_name='bbb', year_start='1998', year_end='2005')
91
+ </code>
92
+
93
+ <code>
94
+ featured_articles = _my_tool_wiki_featured_articles(month='January', year=2005)
95
+ </code>
96
+
97
+ <code>
98
+ bookshelves = _my_tool_libretexts_bookshelves()
99
+ </code>
100
+
101
+ <code>
102
+ books = _my_tool_libretexts_books(bookshelf_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry')
103
+ </code>
104
+
105
+ <code>
106
+ book_sections = _my_tool_libretexts_book_sections(book_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)')
107
+ </code>
108
+
109
+ <code>
110
+ book_section_paragraphs = _my_tool_libretexts_book_section_paragraphs(section_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)/03%3A_Reactions')
111
+ </code>
112
+
113
+ <code>
114
+ paragraph_contents = _my_tool_libretexts_paragraph_contents(paragraph_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)/03%3A_Reactions/3.01%3A_Thermodynamics')
115
+ </code>
116
+
117
+ <code>
118
+ results = web_search("question")
119
+ </code>
120
+
121
+ <code>
122
+ result = visit_webpage("https://www.site1.com/page1")
123
+ </code>
124
+
125
+ <code>
126
+ import os
127
+ print("Some information")
128
+ </code>
129
+
130
+ <code>
131
+ import os
132
+ print(\"\"\"
133
+ Some information
134
+ which has
135
+ many lines
136
+ \"\"\")
137
+ </code>
138
+
139
+ <code>
140
+ final_answer("1")
141
+ </code>
142
+
143
+ <code>
144
+ final_answer("Word")
145
+ </code>
146
+
147
+ <code>
148
+ final_answer("list,of,words")
149
+ </code>
150
+
151
+
152
  """,
153
  planning=PlanningPromptTemplate(
154
+ initial_plan="",
155
+ update_plan_pre_messages="",
156
+ update_plan_post_messages="",
 
 
 
 
 
 
157
  ),
158
  managed_agent=ManagedAgentPromptTemplate(task="", report=""),
159
  final_answer=FinalAnswerPromptTemplate(
160
+ pre_messages="""
 
 
 
161
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of
162
  numbers and/or strings.
163
  If you are asked for a number, don’t use comma to write your number neither use units such as $ or
 
166
  and write the digits in plain text unless specified otherwise.
167
  If you are asked for a comma separated list, apply the above rules depending of whether the element
168
  to be put in the list is a number or a string
169
+
170
+ Report your answer using final_answer tool as below
171
+
172
+ <code>
173
+ final_answer("YOUR FINAL ANSWER")
174
+ </code>
175
+
176
+
177
+ """,
178
+ post_messages="",
179
  ),
180
  )
181
 
my_tool_excel_load.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+ import requests
3
+ import pandas as pd
4
+ from io import BytesIO
5
+ from typing import Any
6
+
7
+ #AUTHORIZED_TYPES = [
8
+ # "string",
9
+ # "boolean",
10
+ # "integer",
11
+ # "number",
12
+ # "image",
13
+ # "audio",
14
+ # "array",
15
+ # "object",
16
+ # "any",
17
+ # "null",
18
+ #]
19
+
20
+
21
+ class ExcelLoadTool(Tool):
22
+ name = "_my_tool_excel_load"
23
+ description = """
24
+ Load Excel spreadsheet for the provided task id
25
+ To invoke the tool use code as below
26
+ <code>
27
+ contents = _my_tool_excel_load(task_id="dummy")
28
+ </code>
29
+ """
30
+
31
+ inputs = {
32
+ "task_id": {
33
+ "type": "string",
34
+ "description": "task id to load excel file",
35
+ }
36
+ }
37
+
38
+ output_type = "any"
39
+ api_url = "https://agents-course-unit4-scoring.hf.space"
40
+
41
+ def forward(self, task_id: str) -> Any:
42
+ headers = {
43
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
44
+ }
45
+ url = f"{self.api_url}/files/{task_id}"
46
+ response = requests.get(url, headers=headers)
47
+ bt = BytesIO(response.content)
48
+ df = pd.read_excel(bt)
49
+ #print(f"***KS*** Loaded Excel file contents for \n\ttask id: {task_id} \n\timage: {df}")
50
+ return df
my_tool_python_load.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import Tool
2
+ import requests
3
+ from io import BytesIO
4
+ from typing import Any
5
+
6
+ #AUTHORIZED_TYPES = [
7
+ # "string",
8
+ # "boolean",
9
+ # "integer",
10
+ # "number",
11
+ # "image",
12
+ # "audio",
13
+ # "array",
14
+ # "object",
15
+ # "any",
16
+ # "null",
17
+ #]
18
+
19
+
20
+ class PythonLoadTool(Tool):
21
+ name = "_my_tool_python_load"
22
+ description = """
23
+ Load file with Python source code for the provided task id
24
+ To invoke the tool use code as below
25
+ <code>
26
+ contents = _my_tool_python_load(task_id="dummy")
27
+ </code>
28
+ """
29
+
30
+ inputs = {
31
+ "task_id": {
32
+ "type": "string",
33
+ "description": "task id to load Python source code file",
34
+ }
35
+ }
36
+
37
+ output_type = "string"
38
+ api_url = "https://agents-course-unit4-scoring.hf.space"
39
+
40
+ def forward(self, task_id: str) -> Any:
41
+ headers = {
42
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
43
+ }
44
+ url = f"{self.api_url}/files/{task_id}"
45
+ response = requests.get(url, headers=headers)
46
+ return response.content.decode('utf-8')
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  gradio
2
  requests
3
  smolagents
 
4
  gradio[oauth]
5
  pytest
6
  matplotlib
@@ -13,4 +14,8 @@ wikitextparser
13
  mwparserfromhell
14
  lxml
15
  cssselect
16
- html-to-markdown
 
 
 
 
 
1
  gradio
2
  requests
3
  smolagents
4
+ smolagents[transformers]
5
  gradio[oauth]
6
  pytest
7
  matplotlib
 
14
  mwparserfromhell
15
  lxml
16
  cssselect
17
+ html-to-markdown
18
+ transformers
19
+ pandas
20
+ openpyxl
21
+ markdownify
test_tools.py CHANGED
@@ -5,14 +5,33 @@ from my_tool_fen import FENTool
5
  from my_tool_chess_analysis import ChessAnalysisTool
6
  from my_tool_wiki_page_section import MyWikiPageSectionTool
7
  from my_tool_wiki_filter_tables import MyWikiTableFilterTool
8
- from my_base_wiki_api import MyWikiAPI
9
  from my_tool_wiki_featured_articles import MyWikiFeaturedArticles
10
  from my_base_libretexts_api import MyLibreTextsAPI
 
 
11
  import pytest
12
  import matplotlib as mp
13
 
14
  #pytest --capture=no
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  @pytest.mark.parametrize("_exp", [("Introductory")])
17
  def test_tool_libretextx_bookshelves(_exp):
18
  api = MyLibreTextsAPI()
 
5
  from my_tool_chess_analysis import ChessAnalysisTool
6
  from my_tool_wiki_page_section import MyWikiPageSectionTool
7
  from my_tool_wiki_filter_tables import MyWikiTableFilterTool
 
8
  from my_tool_wiki_featured_articles import MyWikiFeaturedArticles
9
  from my_base_libretexts_api import MyLibreTextsAPI
10
+ from my_tool_excel_load import ExcelLoadTool
11
+ from my_tool_python_load import PythonLoadTool
12
  import pytest
13
  import matplotlib as mp
14
 
15
  #pytest --capture=no
16
 
17
+ @pytest.mark.parametrize("_task_id,_exp", [("f918266a-b3e0-4914-865d-4faa564f1aef", "")])
18
+ def test_tool_python_load(_task_id,_exp):
19
+ print(f"\nLoading Python file for task id: {_task_id}")
20
+ t = PythonLoadTool()
21
+ result = t.forward(_task_id)
22
+ print(f"Got result:\n{result}")
23
+ assert True
24
+
25
+ @pytest.mark.skip(reason="disabled")
26
+ @pytest.mark.parametrize("_task_id,_exp", [("7bd855d8-463d-4ed5-93ca-5fe35145f733", "")])
27
+ def test_tool_excel_load(_task_id,_exp):
28
+ print(f"\nLoading Excel file for task id: {_task_id}")
29
+ t = ExcelLoadTool()
30
+ result = t.forward(_task_id)
31
+ print(f"Got result:\n{result}")
32
+ assert True
33
+
34
+ @pytest.mark.skip(reason="disabled")
35
  @pytest.mark.parametrize("_exp", [("Introductory")])
36
  def test_tool_libretextx_bookshelves(_exp):
37
  api = MyLibreTextsAPI()