if (finishReason === "stop") {
console.log(message.content)
console.log("AGENT ENDING")
return
} else if (finishReason === "tool_calls") {
for (const toolCall of toolCalls) {
const functionName = toolCall.function.name
const functionToCall = availableFunctions[functionName]
const functionResponse = await functionToCall()
console.log(functionResponse)
}
}
// }
}
await agent("What's the current weather in Tokyo and New York City and Oslo?")
/**
{
"index": 0,
"message": {
"role": "assistant",
"content": "As an AI, I don't have feelings, but I'm here to assist you with any questions
or tasks you have. How can I help you today?"
},
"finish_reason": "stop"
}
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_SDhXnJbvxSWwy1m1R1J43EmQ",
"type": "function",
"function": {
"name": "getLocation",
"arguments": "{}"
}
}
]
},
"finish_reason": "tool_calls"
}
*/