Spaces:
Runtime error
Runtime error
Refactor app.py
Browse filesRemoved the Tool class definition and the calculator_tool invocation that was causing issues.
app.py
CHANGED
|
@@ -7,66 +7,6 @@ from tools.final_answer import FinalAnswerTool
|
|
| 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 |
|
| 71 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 72 |
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 12 |
|