mgbam commited on
Commit
9f79cce
·
verified ·
1 Parent(s): 83bf8d6

Create tool_handler.py import json

Browse files
Files changed (1) hide show
  1. tool_handler.py import json +41 -0
tool_handler.py import json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # rentbot/tool_handler.py
2
+ import json
3
+
4
+ def execute_tool_call(tool_call):
5
+ """
6
+ Executes a tool call and returns a result message for the LLM.
7
+ """
8
+ function_name = tool_call.function.name
9
+ try:
10
+ arguments = json.loads(tool_call.function.arguments)
11
+
12
+ if function_name == "create_event":
13
+ # In a real app, you'd hit Google Calendar's API here.
14
+ # For this example, we'll just simulate success.
15
+ print(f"--- TOOL CALL: create_event ---")
16
+ print(f" Summary: {arguments.get('summary')}")
17
+ print(f" Start: {arguments.get('start_time')}")
18
+ print(f" Duration: {arguments.get('duration_minutes', 30)} minutes")
19
+ print(f"-----------------------------")
20
+
21
+ result_message = f"Successfully booked the viewing for '{arguments.get('summary')}'."
22
+ return {
23
+ "tool_call_id": tool_call.id,
24
+ "role": "tool",
25
+ "name": function_name,
26
+ "content": json.dumps({"status": "success", "message": result_message}),
27
+ }
28
+ else:
29
+ return {
30
+ "tool_call_id": tool_call.id,
31
+ "role": "tool",
32
+ "name": function_name,
33
+ "content": json.dumps({"status": "error", "message": f"Unknown function: {function_name}"}),
34
+ }
35
+ except json.JSONDecodeError:
36
+ return {
37
+ "tool_call_id": tool_call.id,
38
+ "role": "tool",
39
+ "name": function_name,
40
+ "content": json.dumps({"status": "error", "message": "Invalid arguments format."}),
41
+ }