import "./instrumentation";
import OpenAI from "openai";
const openai = new OpenAI();
const tools = [
{
type: "function" as const,
function: {
name: "get_current_weather",
description: "Get the current weather in a given location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
unit: { type: "string", enum: ["celsius", "fahrenheit"] },
},
required: ["location"],
},
},
},
];
async function runFunctionCall() {
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "What's the weather in Boston?" }],
tools: tools,
tool_choice: "auto",
});
const toolCall = response.choices[0].message.tool_calls?.[0];
if (toolCall) {
console.log("Function called:", toolCall.function.name);
console.log("Arguments:", toolCall.function.arguments);
}
}
runFunctionCall();