in components/app.tsx [194:235]
async function handleToolCall(output: any) {
const toolCall = {
name: output.name,
arguments: output.arguments,
};
console.log("Tool call:", toolCall);
setToolCall(toolCall);
// TOOL CALL HANDLING
// Initialize toolCallOutput with a default response
const toolCallOutput: ToolCallOutput = {
response: `Tool call ${toolCall.name} executed successfully.`,
};
// Handle special tool calls
if (toolCall.name === "get_iss_position") {
const issPosition = await fetch("/api/iss").then((response) =>
response.json()
);
console.log("ISS position:", issPosition);
toolCallOutput.issPosition = issPosition;
}
sendClientEvent({
type: "conversation.item.create",
item: {
type: "function_call_output",
call_id: output.call_id,
output: JSON.stringify(toolCallOutput),
},
});
// Force a model response to make sure it responds after certain tool calls
if (
toolCall.name === "get_iss_position" ||
toolCall.name === "display_data"
) {
sendClientEvent({
type: "response.create",
});
}
}