PooriaT commited on
Commit
9c0c793
·
verified ·
1 Parent(s): 6a55cda

Updating my_custom_tool

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -11,12 +11,20 @@ from Gradio_UI import GradioUI
11
  @tool
12
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -34,6 +42,20 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
  model = HfApiModel(
39
  max_tokens=2096,
 
11
  @tool
12
  def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
+ """A tool that combines the arguments and performs a simple calculation.
15
+
16
  Args:
17
+ arg1: A string.
18
+ arg2: An integer.
19
+
20
  """
21
+ try:
22
+ result = int(arg1) * arg2 # Attempt conversion and multiplication
23
+ return f"The result of {arg1} * {arg2} is: {result}"
24
+ except ValueError:
25
+ return "Error: arg1 must be convertible to an integer."
26
+ except Exception as e:
27
+ return f"An unexpected error occurred: {e}"
28
 
29
  @tool
30
  def get_current_time_in_timezone(timezone: str) -> str:
 
42
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
43
 
44
 
45
+ @tool
46
+ def fetch_webpage_content(url: str) -> str:
47
+ """Fetches the content of a webpage.
48
+
49
+ Args:
50
+ url: The URL of the webpage to fetch.
51
+ """
52
+ try:
53
+ response = requests.get(url, timeout=10) # Added timeout for safety
54
+ response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
55
+ return response.text
56
+ except requests.exceptions.RequestException as e:
57
+ return f"Error fetching URL '{url}': {e}"
58
+
59
  final_answer = FinalAnswerTool()
60
  model = HfApiModel(
61
  max_tokens=2096,