UNPKG

ai

Version:

AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.

40 lines (30 loc) 1.07 kB
--- title: useChat No Response description: Troubleshooting errors related to the Use Chat Failed to Parse Stream error. --- # `useChat` No Response ## Issue I am using [`useChat`](/docs/reference/ai-sdk-ui/use-chat). When I log the incoming messages on the server, I can see the tool call and the tool result, but the model does not respond with anything. ## Solution To resolve this issue, convert the incoming messages to the `ModelMessage` format using the [`convertToModelMessages`](/docs/reference/ai-sdk-ui/convert-to-model-messages) function. ```tsx highlight="15" import { openai } from '@ai-sdk/openai'; import { convertToModelMessages, createUIMessageStreamResponse, streamText, toUIMessageStream, } from 'ai'; __PROVIDER_IMPORT__; export async function POST(req: Request) { const { messages } = await req.json(); const result = streamText({ model: __MODEL__, messages: await convertToModelMessages(messages), }); return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }), }); } ```