felixmortas commited on
Commit
f0d2e2f
·
1 Parent(s): 9937931

Remove unnecessary task_id argument from tools

Browse files
Files changed (2) hide show
  1. custom_tools.py +11 -15
  2. utils.py +2 -2
custom_tools.py CHANGED
@@ -138,22 +138,21 @@ def wiki_search(query: str) -> str:
138
  return f"An unexpected error occurred: {e}"
139
 
140
  @tool
141
- def sum_excel_cols(task_id: str, file_name: str, column_names: List[str]) -> float:
142
  """
143
  Sum the values of specified columns in a pandas DataFrame read from an Excel file.
144
 
145
  Args:
146
- task_id (str): The ID of the task.
147
  file_name (str): The path to the Excel file.
148
- column_names (List[str]): A list of column names to sum.
149
 
150
  Returns:
151
  float: The sum of the specified columns.
152
 
153
  Example:
154
- sum_excel_cols("task123", "data.xlsx", ["Column1", "Column2"]) -> 100.0
155
  """
156
- file_status = download_file(task_id, file_name)
157
 
158
  if not os.path.exists(file_name):
159
  return f"File {file_name} does not exist."
@@ -211,18 +210,17 @@ def youtube_transcript(url: str) -> str:
211
 
212
 
213
  @tool
214
- def read_file_content(task_id: str, file_name: str) -> str:
215
  """
216
- Read the text from a file and return its content as a string.
217
 
218
  Args:
219
- task_id (str): The unique identifier for the task.
220
  file_name (str): The name of the file.
221
 
222
  Returns:
223
  str: The content of the file, or a detailed error message.
224
  """
225
- download_state = download_file(task_id, file_name)
226
  if download_state == f"Success downloading {file_name}":
227
  file_content = read_file(file_name)
228
 
@@ -268,11 +266,10 @@ def analyse_youtube_video(url: str, video_question: str):
268
 
269
 
270
  @tool
271
- def analyze_image(task_id: str, file_name: str, question: str) -> str:
272
  """
273
  Download and analyze an image based on a given question.
274
  Args:
275
- task_id (str): The ID of the task.
276
  file_name (str): The name of the image file.
277
  question (str): The question to be answered about the image.
278
  Returns:
@@ -280,7 +277,7 @@ def analyze_image(task_id: str, file_name: str, question: str) -> str:
280
  """
281
  try:
282
  if not os.path.exists(file_name):
283
- file_status = download_file(task_id, file_name)
284
 
285
  if not os.path.exists(file_name):
286
  return f"File {file_name} does not exist : {file_status}"
@@ -301,17 +298,16 @@ def analyze_image(task_id: str, file_name: str, question: str) -> str:
301
 
302
  # Build a tool to transcript a sound .mp3 file with a LLM, based on the filename as a parameter
303
  @tool
304
- def transcript_audio(task_id: str, file_name: str) -> str:
305
  """ Generate a transcript for an audio file using a language model.
306
  Args:
307
- task_id (str): The ID of the task.
308
  file_name (str): The name of the image file.
309
  Returns:
310
  str: A transcript of the audio.
311
  """
312
  # Download the image file if not already present
313
  if not os.path.exists(file_name):
314
- file_status = download_file(task_id, file_name)
315
 
316
  # Check if the file exists
317
  if not os.path.exists(file_name):
 
138
  return f"An unexpected error occurred: {e}"
139
 
140
  @tool
141
+ def sum_excel_cols(file_name: str, column_names: List[str]) -> float:
142
  """
143
  Sum the values of specified columns in a pandas DataFrame read from an Excel file.
144
 
145
  Args:
 
146
  file_name (str): The path to the Excel file.
147
+ column_names (List[str]): A list of column names to sum. The column names need to exist and should be extracted from the input of the read_file_content tool
148
 
149
  Returns:
150
  float: The sum of the specified columns.
151
 
152
  Example:
153
+ sum_excel_cols("data.xlsx", ["Column1", "Column2"]) -> 100.0
154
  """
155
+ file_status = download_file(file_name)
156
 
157
  if not os.path.exists(file_name):
158
  return f"File {file_name} does not exist."
 
210
 
211
 
212
  @tool
213
+ def read_file_content(file_name: str) -> str:
214
  """
215
+ Read the text from an input file and return its content as a string.
216
 
217
  Args:
 
218
  file_name (str): The name of the file.
219
 
220
  Returns:
221
  str: The content of the file, or a detailed error message.
222
  """
223
+ download_state = download_file(file_name)
224
  if download_state == f"Success downloading {file_name}":
225
  file_content = read_file(file_name)
226
 
 
266
 
267
 
268
  @tool
269
+ def analyze_image(file_name: str, question: str) -> str:
270
  """
271
  Download and analyze an image based on a given question.
272
  Args:
 
273
  file_name (str): The name of the image file.
274
  question (str): The question to be answered about the image.
275
  Returns:
 
277
  """
278
  try:
279
  if not os.path.exists(file_name):
280
+ file_status = download_file(file_name)
281
 
282
  if not os.path.exists(file_name):
283
  return f"File {file_name} does not exist : {file_status}"
 
298
 
299
  # Build a tool to transcript a sound .mp3 file with a LLM, based on the filename as a parameter
300
  @tool
301
+ def transcript_audio(file_name: str) -> str:
302
  """ Generate a transcript for an audio file using a language model.
303
  Args:
 
304
  file_name (str): The name of the image file.
305
  Returns:
306
  str: A transcript of the audio.
307
  """
308
  # Download the image file if not already present
309
  if not os.path.exists(file_name):
310
+ file_status = download_file(file_name)
311
 
312
  # Check if the file exists
313
  if not os.path.exists(file_name):
utils.py CHANGED
@@ -12,17 +12,17 @@ from typing import List
12
 
13
 
14
 
15
- def download_file(task_id: str, file_name: str) -> str:
16
  """
17
  Download a file from a given task ID and save it to the local filesystem.
18
 
19
  Args:
20
- task_id (str): The ID of the task whose file is to be downloaded.
21
  file_name (str): The name of the file to be saved.
22
 
23
  Returns:
24
  str: A message indicating the result of the download operation.
25
  """
 
26
  url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
27
 
28
  try:
 
12
 
13
 
14
 
15
+ def download_file(file_name: str) -> str:
16
  """
17
  Download a file from a given task ID and save it to the local filesystem.
18
 
19
  Args:
 
20
  file_name (str): The name of the file to be saved.
21
 
22
  Returns:
23
  str: A message indicating the result of the download operation.
24
  """
25
+ task_id = file_name.split(".")[0].split("/")[-1]
26
  url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
27
 
28
  try: