|
|
|
|
|
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": |
|
|
|
|
|
|
|
|
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."}), |
|
|
} |