In this code how do I define the get_weather_function so that it is actually called and returns the static response?
export async function POST({ request }) {
const { messages } = await request.json();
console.log(messages, 'request')
const tools = [
{
"type": "function",
"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"],
},
}
}
];
const initialMessage = {
role: "system",
content: " Your name is Tina, please keep your responses succint when possible."
};
const updatedMessages = [initialMessage, ...messages];
// Ask OpenAI for a streaming chat completion given the prompt
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo', //gpt-4-1106-preview gpt-3.5-turbo gpt-4-0125-preview // does not work gpt-4-1106-vision-preview
stream: true,
messages:updatedMessages,
tools: tools,
tool_choice: "auto",
});
// Convert the response into a friendly text-stream
const stream = OpenAIStream(response);
// Respond with the stream
return new StreamingTextResponse(stream);
}