Final_Test / tool /UnknownTextTool.py
David Kovář
force rebuild
ded8dc7
from smolagents import Tool
class UnknownTextTool(Tool):
name = "unknown_text_tool"
description = "Returns the reversed version of the text. If you receive some unknown text, that can't be recognized and analyzed, then you need to use this tool to make it clear."
inputs = {
"query": {
"type": "string",
"description": "Unknown text to be decoded"
}
}
output_type = "string"
def forward(self, query):
try:
print(f"Reversed text: {query[::-1]}")
return query[::-1]
except Exception as e:
return f"Can't reverse text: {e}"
class BasicMathTool(Tool):
name = "basic_math_tool"
description = "Performs basic arithmetic operations (addition, subtraction, multiplication, division...)"
inputs = {
"operation": {
"type": "string",
"description": "Mathematical operation to perform (+, -, *, /)"
},
"x": {
"type": "number",
"description": "First number"
},
"y": {
"type": "number",
"description": "Second number"
}
}
output_type = "number"
def forward(self, operation, x, y):
try:
if operation == "+":
return x + y
elif operation == "-":
return x - y
elif operation == "*":
return x * y
elif operation == "/":
if y == 0:
raise ValueError("Division by zero")
return x / y
else:
raise ValueError(f"Unknown operation: {operation}")
except Exception as e:
return f"Math error: {e}"