Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,68 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
def get_domain_ip(domain:str)-> str: #it's important to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
@@ -23,11 +84,20 @@ def get_domain_ip(domain:str)-> str: #it's important to specify the return type
|
|
23 |
try:
|
24 |
# Create a domain object
|
25 |
domain = domain
|
26 |
-
domain_info =
|
27 |
return f"A summary of the '{domain}' domain and contact details: {domain_info}"
|
28 |
except Exception as e:
|
29 |
return f"Error fetching domain for {domain} whois lookup: {e}"
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
@tool
|
32 |
def get_current_time_in_timezone(timezone: str) -> str:
|
33 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
#
|
11 |
+
|
12 |
+
|
13 |
+
# This is a class dedicated for creating tools
|
14 |
+
|
15 |
+
class Tool:
|
16 |
+
"""
|
17 |
+
A class representing a reusable piece of code (Tool).
|
18 |
+
|
19 |
+
Attributes:
|
20 |
+
name (str): Name of the tool.
|
21 |
+
description (str): A textual description of what the tool does.
|
22 |
+
func (callable): The function this tool wraps.
|
23 |
+
arguments (list): A list of argument.
|
24 |
+
outputs (str or list): The return type(s) of the wrapped function.
|
25 |
+
"""
|
26 |
+
def __init__(self,
|
27 |
+
name: str,
|
28 |
+
description: str,
|
29 |
+
func: callable,
|
30 |
+
arguments: list,
|
31 |
+
outputs: str):
|
32 |
+
self.name = name
|
33 |
+
self.description = description
|
34 |
+
self.func = func
|
35 |
+
self.arguments = arguments
|
36 |
+
self.outputs = outputs
|
37 |
+
|
38 |
+
def to_string(self) -> str:
|
39 |
+
"""
|
40 |
+
Return a string representation of the tool,
|
41 |
+
including its name, description, arguments, and outputs.
|
42 |
+
"""
|
43 |
+
args_str = ", ".join([
|
44 |
+
f"{arg_name}: {arg_type}" for arg_name, arg_type in self.arguments
|
45 |
+
])
|
46 |
+
|
47 |
+
return (
|
48 |
+
f"Tool Name: {self.name,}"
|
49 |
+
f"Description: {self.description,}"
|
50 |
+
f"Arguments: {args_str},"
|
51 |
+
f"Outputs: {self.outputs}"
|
52 |
+
)
|
53 |
+
|
54 |
+
def __call__(self, *args, **kwargs):
|
55 |
+
"""
|
56 |
+
Invoke the underlying function (callable) with provided arguments.
|
57 |
+
"""
|
58 |
+
|
59 |
+
return self.func(*args, **kwargs)
|
60 |
+
|
61 |
+
# Here are tools created the Tool class
|
62 |
+
|
63 |
+
calculator_tool = Tool(
|
64 |
+
"calculator",
|
65 |
+
"Multiply",
|
66 |
+
calculator,
|
67 |
+
[("a", "int"), ("b", "int")],
|
68 |
+
"int",
|
69 |
+
|
70 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
71 |
+
|
72 |
@tool
|
73 |
def get_domain_ip(domain:str)-> str: #it's important to specify the return type
|
74 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
84 |
try:
|
85 |
# Create a domain object
|
86 |
domain = domain
|
87 |
+
domain_info = (domain)
|
88 |
return f"A summary of the '{domain}' domain and contact details: {domain_info}"
|
89 |
except Exception as e:
|
90 |
return f"Error fetching domain for {domain} whois lookup: {e}"
|
91 |
|
92 |
+
@tool
|
93 |
+
def calculator(a: int, b: int) -> int:
|
94 |
+
"""Multiply two integers."""
|
95 |
+
return a * b
|
96 |
+
|
97 |
+
print(calculator_tool.to_string())
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
@tool
|
102 |
def get_current_time_in_timezone(timezone: str) -> str:
|
103 |
"""A tool that fetches the current local time in a specified timezone.
|