⚡ (openai) Use Vercel's AI SDK for streaming
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { getChatCompletionStream } from '@/features/blocks/integrations/openai/getChatCompletionStream'
|
||||
import { connect } from '@planetscale/database'
|
||||
import { IntegrationBlockType, SessionState } from '@typebot.io/schemas'
|
||||
import { StreamingTextResponse } from 'ai'
|
||||
import { ChatCompletionRequestMessage } from 'openai'
|
||||
|
||||
export const config = {
|
||||
@ -15,8 +16,7 @@ const handler = async (req: Request) => {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'POST',
|
||||
'Access-Control-Expose-Headers': 'Content-Length, X-JSON',
|
||||
'Access-Control-Allow-Headers':
|
||||
'apikey,X-Client-Info, Content-Type, Authorization, Accept, Accept-Language, X-Authorization',
|
||||
'Access-Control-Allow-Headers': '*',
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -66,12 +66,10 @@ const handler = async (req: Request) => {
|
||||
messages
|
||||
)
|
||||
|
||||
if (!stream) return new Response('Missing credentials', { status: 400 })
|
||||
if (!stream) return new Response('Could not create stream', { status: 400 })
|
||||
|
||||
return new Response(stream, {
|
||||
status: 200,
|
||||
return new StreamingTextResponse(stream, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
},
|
||||
})
|
||||
|
Reference in New Issue
Block a user