Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdded the roman_calculutor_convert function. And added the functions to the tools list.
app.py
CHANGED
|
@@ -18,6 +18,40 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -37,12 +71,13 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
|
| 42 |
model = HfApiModel(
|
| 43 |
max_tokens=2096,
|
| 44 |
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
|
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
@@ -55,7 +90,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def roman_calculator_converter(value1:int, value2:int, oper:str) -> str:
|
| 23 |
+
"""A tool that performs an operator on 2 numbers to calculate the result
|
| 24 |
+
Args:
|
| 25 |
+
value1: the first value
|
| 26 |
+
value2: the second value
|
| 27 |
+
oper: operator for the calculation, like "add", "substract", "multiply", "divide"
|
| 28 |
+
"""
|
| 29 |
+
roman_numerals = {
|
| 30 |
+
1000: "M", 900: "CM", 500: "D", 400: "CD",
|
| 31 |
+
100: "C", 90: "XC", 50: "L", 40: "XL",
|
| 32 |
+
10: "X", 9: "IX", 5: "V", 4: "IV", 1: "I"
|
| 33 |
+
}
|
| 34 |
+
roman_string = ""
|
| 35 |
+
|
| 36 |
+
if oper = "add":
|
| 37 |
+
result = value1 + value2
|
| 38 |
+
elif oper == "subtract":
|
| 39 |
+
result = value2 - value1
|
| 40 |
+
elif oper == "divide":
|
| 41 |
+
result = value1 / value2
|
| 42 |
+
elif oper == "multiply":
|
| 43 |
+
result = value1 * value2
|
| 44 |
+
|
| 45 |
+
else:
|
| 46 |
+
return "Unsupported operation. Please use 'add' or 'subtract'."
|
| 47 |
+
|
| 48 |
+
for value, numeral in roman_numerals.items():
|
| 49 |
+
while result >= value:
|
| 50 |
+
roman_string += numeral
|
| 51 |
+
result -= value
|
| 52 |
+
return f"The result of {oper} on the values {value1} and {value2} is the Roman numeral: {roman_string}"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
@tool
|
| 56 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 57 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 71 |
final_answer = FinalAnswerTool()
|
| 72 |
|
| 73 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 74 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 75 |
|
| 76 |
model = HfApiModel(
|
| 77 |
max_tokens=2096,
|
| 78 |
temperature=0.5,
|
| 79 |
+
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 80 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
|
| 81 |
custom_role_conversions=None,
|
| 82 |
)
|
| 83 |
|
|
|
|
| 90 |
|
| 91 |
agent = CodeAgent(
|
| 92 |
model=model,
|
| 93 |
+
tools=[final_answer, image_generation_tool, get_current_time_in_timezone, roman_calculator_converter], ## add your tools here (don't remove final answer)
|
| 94 |
max_steps=6,
|
| 95 |
verbosity_level=1,
|
| 96 |
grammar=None,
|