最近使用Next.js框架开发gpt-4应用,发现调用gpt-4返回结果是超过30秒就出现timeout提示。在fetch函数添加各种timeout选项问题依然存在。后面找寻时发现:
“Edge Functions have a timeout of 30 seconds and even longer when streaming, which far exceeds the timeout limit for serverless functions on Vercel’s Hobby plan. Using these can allow you to get past timeout issues when using AI APIs that take longer to respond. As an added benefit, Edge Functions are also cheaper to run.”
也就是说使用streaming功能的函数(包含ReadableStream关键字)必须是edge,即在函数后面添加:
export const runtime = “edge”;
这样即使超过30秒也不会报错。
https://vercel.com/docs/concepts/functions/edge-functions/streaming