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{openai}from'@ai-sdk/openai';import{streamText}from'ai';// Allow streaming responses up to 30 secondsexportconstmaxDuration=30;exportasyncfunctionPOST(req: Request){const{ messages }=awaitreq.json();constresult=streamText({model: openai('gpt-4-turbo'),system: 'You are a helpful assistant.',
messages,});console.log(result.response);returnresult.toDataStreamResponse();}
I have introduced an onError callback on streamText: #4729 (ai@4.1.22)
streamText immediately starts streaming to enable sending data without waiting for the model.
Errors become part of the stream and are not thrown to prevent e.g. servers from crashing.
To log errors, you can provide an onError callback that is triggered when an error occurs.
import{streamText}from'ai';constresult=streamText({model: yourModel,prompt: 'Invent a new holiday and describe its traditions.',onError({ error }){console.error(error);// your error logging logic here},});
Description
and nothing repond i try to console reponce give me that
and nothing repond i try to console reponce give me that
Response {
status: 200,
statusText: '',
headers: Headers {
'Content-Type': 'text/plain; charset=utf-8',
'X-Vercel-AI-Data-Stream': 'v1'
},
body: ReadableStream { locked: false, state: 'readable', supportsBYOB: false },
bodyUsed: false,
ok: true,
redirected: false,
type: 'default',
url: ''
}
Code example
app/api/chat/route.tsx :
https://www.codebin.cc/code/cm6ow886c0001jl03nr6bvtuv:5vUaFjyKdGLEUhgcqHYrDCkd1MccVkL5W69vWkoXe6sc
app/chat/page.tsx:
https://www.codebin.cc/code/cm6ow97iv0001l2031qix4xb2:Cu13SzXkuQwwsS96pUSVdXk7B17jNEGM7hgteLe188zD
AI provider
"@ai-sdk/openai": "^1.1.9",
Additional context
No response
The text was updated successfully, but these errors were encountered: