huytofu92 commited on
Commit
737c21b
·
1 Parent(s): 8a0cdd8

redefine tools

Browse files
Files changed (1) hide show
  1. tools.py +7 -7
tools.py CHANGED
@@ -97,7 +97,7 @@ def operate_two_numbers(num1: float, num2: float, operation: Literal["add", "sub
97
  raise ValueError("operation must be one of the following: add, subtract, multiply, divide, power, modulo")
98
 
99
  @tool
100
- def convert_number(orig_num: Union[float, int], operation: Literal["to_base", "type_cast"], new_base: Literal["binary", "octal", "hexadecimal", "int", "float"], decimal_places: int = 2)->Union[int, float]:
101
  """
102
  Convert a number to a new base
103
  Args:
@@ -113,7 +113,7 @@ def convert_number(orig_num: Union[float, int], operation: Literal["to_base", "t
113
  - "float": Convert the number to a float.
114
  decimal_places: The number of decimal places to round the result to. Default is 2. Only used if operation is "type_cast" and new_base is "float".
115
  Returns:
116
- The converted number
117
  """
118
  if operation == "to_base":
119
  if new_base == "binary":
@@ -149,7 +149,7 @@ def to_json(data: pd.DataFrame)->str:
149
  return data.to_json(orient="records")
150
 
151
  @tool
152
- def get_dataframe_data(data: pd.DataFrame, column: Union[str, int], row: Union[str, int])->Union[str, int, float]:
153
  """
154
  Get a specific cell from a pandas DataFrame
155
  Args:
@@ -157,7 +157,7 @@ def get_dataframe_data(data: pd.DataFrame, column: Union[str, int], row: Union[s
157
  column: The column to get the data from. Must be a string or int. If int then it is the index of the column.
158
  row: The row to get the data from. Must be a string or int. If int then it is the index of the row.
159
  Returns:
160
- The data from the specified cell
161
  """
162
  if isinstance(column, int):
163
  column = data.iloc[:, column]
@@ -166,7 +166,7 @@ def get_dataframe_data(data: pd.DataFrame, column: Union[str, int], row: Union[s
166
  return data.loc[row, column]
167
 
168
  @tool
169
- def get_dataframe_column(data: pd.DataFrame, column: Union[str, int])->pd.Series:
170
  """
171
  Get a specific column from a pandas DataFrame
172
  Args:
@@ -178,7 +178,7 @@ def get_dataframe_column(data: pd.DataFrame, column: Union[str, int])->pd.Series
178
  return data.iloc[:, column]
179
 
180
  @tool
181
- def get_dataframe_row(data: pd.DataFrame, row: Union[str, int])->pd.Series:
182
  """
183
  Get a specific row from a pandas DataFrame
184
  Args:
@@ -190,7 +190,7 @@ def get_dataframe_row(data: pd.DataFrame, row: Union[str, int])->pd.Series:
190
  return data.iloc[row, :]
191
 
192
  @tool
193
- def get_dataframe_groupby(data: pd.DataFrame, column: str, operation: Literal["mean", "sum", "count", "min", "max", "median", "std", "var"])->pd.DataFrame:
194
  """
195
  Group a pandas DataFrame by a specific column and perform an operation on the grouped data
196
  Args:
 
97
  raise ValueError("operation must be one of the following: add, subtract, multiply, divide, power, modulo")
98
 
99
  @tool
100
+ def convert_number(orig_num: any, operation: Literal["to_base", "type_cast"], new_base: Literal["binary", "octal", "hexadecimal", "int", "float"], decimal_places: int = 2)->any:
101
  """
102
  Convert a number to a new base
103
  Args:
 
113
  - "float": Convert the number to a float.
114
  decimal_places: The number of decimal places to round the result to. Default is 2. Only used if operation is "type_cast" and new_base is "float".
115
  Returns:
116
+ The converted number. Can be float or int or str.
117
  """
118
  if operation == "to_base":
119
  if new_base == "binary":
 
149
  return data.to_json(orient="records")
150
 
151
  @tool
152
+ def get_dataframe_data(data: pd.DataFrame, column: any, row: any)->any:
153
  """
154
  Get a specific cell from a pandas DataFrame
155
  Args:
 
157
  column: The column to get the data from. Must be a string or int. If int then it is the index of the column.
158
  row: The row to get the data from. Must be a string or int. If int then it is the index of the row.
159
  Returns:
160
+ The data from the specified cell. Can be float or int or str.
161
  """
162
  if isinstance(column, int):
163
  column = data.iloc[:, column]
 
166
  return data.loc[row, column]
167
 
168
  @tool
169
+ def get_dataframe_column(data: pd.DataFrame, column: any)->pd.Series:
170
  """
171
  Get a specific column from a pandas DataFrame
172
  Args:
 
178
  return data.iloc[:, column]
179
 
180
  @tool
181
+ def get_dataframe_row(data: pd.DataFrame, row: any)->pd.Series:
182
  """
183
  Get a specific row from a pandas DataFrame
184
  Args:
 
190
  return data.iloc[row, :]
191
 
192
  @tool
193
+ def get_dataframe_groupby(data: pd.DataFrame, column: any, operation: Literal["mean", "sum", "count", "min", "max", "median", "std", "var"])->pd.DataFrame:
194
  """
195
  Group a pandas DataFrame by a specific column and perform an operation on the grouped data
196
  Args: