Spaces:
Sleeping
Sleeping
add todo_tool * update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,50 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
BASE_URL = "https://ed8mcpow622o.devvapp.ai/api/todos"
|
15 |
+
|
16 |
+
@tool
|
17 |
+
def todo_tool(action: str, title: str = "", description: str = "", todo_id: str = "") -> str:
|
18 |
+
"""A tool for interacting with the Todo API.
|
19 |
+
|
20 |
+
Args:
|
21 |
+
action: The action to perform. Can be 'list', 'create', 'update', or 'delete'.
|
22 |
+
title: The title of the todo (required for 'create' and optional for 'update').
|
23 |
+
description: The description of the todo (optional for 'create' and 'update').
|
24 |
+
todo_id: The ID of the todo item (required for 'update' and 'delete').
|
25 |
+
|
26 |
+
Returns:
|
27 |
+
A string describing the API response.
|
28 |
+
"""
|
29 |
+
|
30 |
+
try:
|
31 |
+
if action == "list":
|
32 |
+
response = requests.get(BASE_URL)
|
33 |
+
elif action == "create":
|
34 |
+
if not title:
|
35 |
+
return "Error: 'title' is required for creating a todo."
|
36 |
+
data = {"title": title, "description": description}
|
37 |
+
response = requests.post(BASE_URL, json=data)
|
38 |
+
elif action == "update":
|
39 |
+
if not todo_id:
|
40 |
+
return "Error: 'todo_id' is required for updating a todo."
|
41 |
+
data = {"title": title, "description": description}
|
42 |
+
response = requests.patch(f"{BASE_URL}/{todo_id}", json=data)
|
43 |
+
elif action == "delete":
|
44 |
+
if not todo_id:
|
45 |
+
return "Error: 'todo_id' is required for deleting a todo."
|
46 |
+
response = requests.delete(f"{BASE_URL}/{todo_id}")
|
47 |
+
else:
|
48 |
+
return "Error: Invalid action. Use 'list', 'create', 'update', or 'delete'."
|
49 |
+
|
50 |
+
return response.text if response.ok else f"Error: {response.status_code} - {response.text}"
|
51 |
+
|
52 |
+
except requests.RequestException as e:
|
53 |
+
return f"Request failed: {str(e)}"
|
54 |
+
|
55 |
@tool
|
56 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
57 |
#Keep this format for the description / args / args description but feel free to modify the tool
|