You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{ToolInvocation,streamText}from'ai';import{openai}from'@ai-sdk/openai';import{z}from'zod';interfaceMessage{role: 'user'|'assistant';content: string;toolInvocations?: ToolInvocation[];}exportasyncfunctionPOST(req: Request){const{ messages }: {messages: Message[]}=awaitreq.json();constresult=streamText({model: openai('gpt-4o'),system: 'You are a helpful assistant.',
messages,tools: {getWeather: {description: 'Get the weather for a location',parameters: z.object({city: z.string().describe('The city to get the weather for'),unit: z.enum(['C','F']).describe('The unit to display the temperature in'),}),execute: async({ city, unit })=>{constweather={value: 24,description: 'Sunny',};return`It is currently ${weather.value}°${unit} and ${weather.description} in ${city}!`;},},},});returnresult.toDataStreamResponse();}
Get blank page when running npm run dev
To Fix, I can give page.tsx to ChatGPT and say fix for blank render, and it gives me this:
Description
copy in code from docs here: https://sdk.vercel.ai/cookbook/next/call-tools
The source files are pasted below (and are identical in the GitHub repo)
This is the broken branch with the issue: https://github.com/pkellner/ai-sdk-chat-issue1/tree/bug-broken-directly-from-ai-sdk-docs
This is the fixed branch with the chat app working as expected: https://github.com/pkellner/ai-sdk-chat-issue1/tree/bug-fixed-by-minor-div-changes
into /src/app/page.tsx:
and /src/app/api/chat/route.ts
Get blank page when running npm run dev
To Fix, I can give page.tsx to ChatGPT and say fix for blank render, and it gives me this:
The text was updated successfully, but these errors were encountered: