🐛 (openai) Fix 2 openai streaming back to back
This commit is contained in:
@@ -39,6 +39,7 @@ export const continueBotFlow = async (
|
||||
reply: string | undefined,
|
||||
{ state, version }: Params
|
||||
): Promise<ChatReply & { newSessionState: SessionState }> => {
|
||||
let firstBubbleWasStreamed = false
|
||||
let newSessionState = { ...state }
|
||||
|
||||
if (!newSessionState.currentBlock) return startBotFlow({ state, version })
|
||||
@@ -81,6 +82,7 @@ export const continueBotFlow = async (
|
||||
block.type === IntegrationBlockType.OPEN_AI &&
|
||||
block.options.task === 'Create chat completion'
|
||||
) {
|
||||
firstBubbleWasStreamed = true
|
||||
if (reply) {
|
||||
const result = await resumeChatCompletion(state, {
|
||||
options: block.options,
|
||||
@@ -125,7 +127,7 @@ export const continueBotFlow = async (
|
||||
...group,
|
||||
blocks: group.blocks.slice(blockIndex + 1),
|
||||
},
|
||||
{ version, state: newSessionState }
|
||||
{ version, state: newSessionState, firstBubbleWasStreamed }
|
||||
)
|
||||
return {
|
||||
...chatReply,
|
||||
@@ -157,6 +159,7 @@ export const continueBotFlow = async (
|
||||
const chatReply = await executeGroup(nextGroup.group, {
|
||||
version,
|
||||
state: newSessionState,
|
||||
firstBubbleWasStreamed,
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -29,11 +29,18 @@ type ContextProps = {
|
||||
state: SessionState
|
||||
currentReply?: ChatReply
|
||||
currentLastBubbleId?: string
|
||||
firstBubbleWasStreamed?: boolean
|
||||
}
|
||||
|
||||
export const executeGroup = async (
|
||||
group: Group,
|
||||
{ version, state, currentReply, currentLastBubbleId }: ContextProps
|
||||
{
|
||||
version,
|
||||
state,
|
||||
currentReply,
|
||||
currentLastBubbleId,
|
||||
firstBubbleWasStreamed,
|
||||
}: ContextProps
|
||||
): Promise<ChatReply & { newSessionState: SessionState }> => {
|
||||
const messages: ChatReply['messages'] = currentReply?.messages ?? []
|
||||
let clientSideActions: ChatReply['clientSideActions'] =
|
||||
@@ -44,10 +51,13 @@ export const executeGroup = async (
|
||||
|
||||
let newSessionState = state
|
||||
|
||||
let index = -1
|
||||
for (const block of group.blocks) {
|
||||
index++
|
||||
nextEdgeId = block.outgoingEdgeId
|
||||
|
||||
if (isBubbleBlock(block)) {
|
||||
if (firstBubbleWasStreamed && index === 0) continue
|
||||
messages.push(
|
||||
parseBubbleBlock(block, {
|
||||
version,
|
||||
|
||||
Reference in New Issue
Block a user