Spaces:
Sleeping
Sleeping
File size: 1,739 Bytes
a08fec1 ded8dc7 a08fec1 f3ac5a1 a08fec1 f3ac5a1 a08fec1 f3ac5a1 a08fec1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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}"
|