EtienneB commited on
Commit
4e8db54
·
1 Parent(s): 05454e1
Files changed (2) hide show
  1. requirements.txt +5 -0
  2. tools.py +14 -6
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  # UI and OAuth
2
  gradio[oauth]
3
  requests
 
4
 
5
  # LangChain and ecosystem
6
  langchain
@@ -15,3 +16,7 @@ accelerate # Needed for many transformer-based models
15
 
16
  # Environment config
17
  python-dotenv
 
 
 
 
 
1
  # UI and OAuth
2
  gradio[oauth]
3
  requests
4
+ pandas
5
 
6
  # LangChain and ecosystem
7
  langchain
 
16
 
17
  # Environment config
18
  python-dotenv
19
+
20
+ # Tools dependencies
21
+ duckduckgo-search # Required for web_search tool
22
+ pytz # Required for get_current_time_in_timezone tool
tools.py CHANGED
@@ -1,5 +1,7 @@
 
1
  import math
2
 
 
3
  from langchain_community.tools import DuckDuckGoSearchRun
4
  from langchain_core.tools import tool
5
 
@@ -196,12 +198,12 @@ def web_search(query: str) -> str:
196
 
197
 
198
  @tool
199
- def roman_calculator_converter(value1:int, value2:int, oper:str) -> str:
200
  """A tool that performs an operator on 2 numbers to calculate the result
201
  Args:
202
  value1: the first value
203
  value2: the second value
204
- oper: operator for the calculation, like "add", "substract", "multiply", "divide"
205
  """
206
  roman_numerals = {
207
  1000: "M", 900: "CM", 500: "D", 400: "CD",
@@ -213,19 +215,25 @@ def roman_calculator_converter(value1:int, value2:int, oper:str) -> str:
213
  if oper == "add":
214
  result = value1 + value2
215
  elif oper == "subtract":
216
- result = value2 - value1
217
  elif oper == "divide":
218
- result = value1 / value2
 
 
219
  elif oper == "multiply":
220
  result = value1 * value2
221
-
222
  else:
223
- return "Unsupported operation. Please use 'add' or 'subtract'."
 
 
 
 
224
 
225
  for value, numeral in roman_numerals.items():
226
  while result >= value:
227
  roman_string += numeral
228
  result -= value
 
229
  return f"The result of {oper} on the values {value1} and {value2} is the Roman numeral: {roman_string}"
230
 
231
 
 
1
+ import datetime
2
  import math
3
 
4
+ import pytz
5
  from langchain_community.tools import DuckDuckGoSearchRun
6
  from langchain_core.tools import tool
7
 
 
198
 
199
 
200
  @tool
201
+ def roman_calculator_converter(value1: int, value2: int, oper: str) -> str:
202
  """A tool that performs an operator on 2 numbers to calculate the result
203
  Args:
204
  value1: the first value
205
  value2: the second value
206
+ oper: operator for the calculation, like "add", "subtract", "multiply", "divide"
207
  """
208
  roman_numerals = {
209
  1000: "M", 900: "CM", 500: "D", 400: "CD",
 
215
  if oper == "add":
216
  result = value1 + value2
217
  elif oper == "subtract":
218
+ result = value1 - value2 # Fixed: was value2 - value1
219
  elif oper == "divide":
220
+ if value2 == 0:
221
+ return "Error: Division by zero is not allowed"
222
+ result = int(value1 / value2) # Convert to int for Roman numerals
223
  elif oper == "multiply":
224
  result = value1 * value2
 
225
  else:
226
+ return "Unsupported operation. Please use 'add', 'subtract', 'multiply', or 'divide'."
227
+
228
+ # Handle negative results
229
+ if result <= 0:
230
+ return f"Error: Roman numerals cannot represent zero or negative numbers. Result was: {result}"
231
 
232
  for value, numeral in roman_numerals.items():
233
  while result >= value:
234
  roman_string += numeral
235
  result -= value
236
+
237
  return f"The result of {oper} on the values {value1} and {value2} is the Roman numeral: {roman_string}"
238
 
239