Download tool_handler.py from mgbam/rentbot: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/mgbam/rentbot/resolve/eae2044d6d7e5b0aea62e74480d60520c795f3b7/tool_handler.py
- Command line
-
hf download hf://spaces/mgbam/rentbot@eae2044d6d7e5b0aea62e74480d60520c795f3b7/tool_handler.py
-
curl -L -o tool_handler.py https://huggingface.co/spaces/mgbam/rentbot/resolve/eae2044d6d7e5b0aea62e74480d60520c795f3b7/tool_handler.py
1.65 kB
| # rentbot/tool_handler.py | |
| import json | |
| def execute_tool_call(tool_call): | |
| """ | |
| Executes a tool call and returns a result message for the LLM. | |
| """ | |
| function_name = tool_call.function.name | |
| try: | |
| arguments = json.loads(tool_call.function.arguments) | |
| if function_name == "create_event": | |
| # In a real app, you'd hit Google Calendar's API here. | |
| # For this example, we'll just simulate success. | |
| print(f"--- TOOL CALL: create_event ---") | |
| print(f" Summary: {arguments.get('summary')}") | |
| print(f" Start: {arguments.get('start_time')}") | |
| print(f" Duration: {arguments.get('duration_minutes', 30)} minutes") | |
| print(f"-----------------------------") | |
| result_message = f"Successfully booked the viewing for '{arguments.get('summary')}'." | |
| return { | |
| "tool_call_id": tool_call.id, | |
| "role": "tool", | |
| "name": function_name, | |
| "content": json.dumps({"status": "success", "message": result_message}), | |
| } | |
| else: | |
| return { | |
| "tool_call_id": tool_call.id, | |
| "role": "tool", | |
| "name": function_name, | |
| "content": json.dumps({"status": "error", "message": f"Unknown function: {function_name}"}), | |
| } | |
| except json.JSONDecodeError: | |
| return { | |
| "tool_call_id": tool_call.id, | |
| "role": "tool", | |
| "name": function_name, | |
| "content": json.dumps({"status": "error", "message": "Invalid arguments format."}), | |
| } |