Skip to content

Commit

Permalink
🚸 (openai) Display OpenAI initial response error
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Aug 2, 2023
1 parent e20e6e7 commit c534613
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ export const getChatCompletionStream =
messages,
})

if (!response.ok) return response

return OpenAIStream(response)
}
15 changes: 12 additions & 3 deletions apps/viewer/src/pages/api/integrations/openai/streamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,24 @@ const handler = async (req: Request) => {
)
return new Response('Current block is not an OpenAI block', { status: 400 })

const stream = await getChatCompletionStream(conn)(
const streamOrResponse = await getChatCompletionStream(conn)(
state,
block.options,
messages
)

if (!stream) return new Response('Could not create stream', { status: 400 })
if (!streamOrResponse)
return new Response('Could not create stream', { status: 400 })

return new StreamingTextResponse(stream, {
if ('ok' in streamOrResponse)
return new Response(streamOrResponse.body, {
status: streamOrResponse.status,
headers: {
'Access-Control-Allow-Origin': '*',
},
})

return new StreamingTextResponse(streamOrResponse, {
headers: {
'Access-Control-Allow-Origin': '*',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.1.13",
"version": "0.1.14",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const ConversationContainer = (props: Props) => {
})

const streamMessage = (content: string) => {
console.log('STREAM', content)
setIsSending(false)
const lastChunk = [...chatChunks()].pop()
if (!lastChunk) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export const streamChat =

if (!res.ok) {
return {
error: {
message: (await res.text()) || 'Failed to fetch the chat response.',
},
error: (await res.json()) || 'Failed to fetch the chat response.',
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.1.13",
"version": "0.1.14",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.1.13",
"version": "0.1.14",
"description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit c534613

Please sign in to comment.