optionEdge commited on
Commit
a1d1bf7
·
verified ·
1 Parent(s): be45560

Update BasicAgent.py

Browse files
Files changed (1) hide show
  1. BasicAgent.py +6 -8
BasicAgent.py CHANGED
@@ -15,17 +15,15 @@ from smolagents import (
15
 
16
  #*
17
  @tool
18
- def read_excel(file_path: str, sheet_name: Union[str, int] = 0) -> Union[str, pd.DataFrame]:
19
  """
20
- Read an Excel file into a pandas DataFrame.
21
- Args:
22
- file_path (str): Path to the Excel file.
23
- sheet_name (Union[str, int]): Sheet name or index. Defaults to 0.
24
- Returns:
25
- DataFrame or error message string.
26
  """
27
  try:
28
- return pd.read_excel(file_path, sheet_name=sheet_name)
 
 
 
29
  except Exception as e:
30
  return f"Error reading Excel file: {e}"
31
  #
 
15
 
16
  #*
17
  @tool
18
+ def read_excel(file_path: str, sheet_name: str = "0") -> str:
19
  """
20
+ Read an Excel file and return it as JSON-like string.
 
 
 
 
 
21
  """
22
  try:
23
+ # Try to convert sheet_name to int if it's a number
24
+ sheet = int(sheet_name) if sheet_name.isdigit() else sheet_name
25
+ df = pd.read_excel(file_path, sheet_name=sheet)
26
+ return df.to_json(orient="records")
27
  except Exception as e:
28
  return f"Error reading Excel file: {e}"
29
  #