Skip to content

Commit 98e75ad

Browse files
authored
Bugfix/ui streaming when model streaming is off (#4424)
fix ui streaming when model streaming is off
1 parent a8f990c commit 98e75ad

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/components/nodes/agentflow/Agent/Agent.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,11 @@ class Agent_Agentflow implements INode {
903903
}
904904
} else if (!humanInput && !isStreamable && isLastNode && sseStreamer) {
905905
// Stream whole response back to UI if not streaming and no tool calls
906-
sseStreamer.streamTokenEvent(chatId, JSON.stringify(response, null, 2))
906+
let responseContent = JSON.stringify(response, null, 2)
907+
if (typeof response.content === 'string') {
908+
responseContent = response.content
909+
}
910+
sseStreamer.streamTokenEvent(chatId, responseContent)
907911
}
908912

909913
// Calculate execution time
@@ -1473,7 +1477,11 @@ class Agent_Agentflow implements INode {
14731477

14741478
// Stream non-streaming response if this is the last node
14751479
if (isLastNode && sseStreamer) {
1476-
sseStreamer.streamTokenEvent(chatId, JSON.stringify(newResponse, null, 2))
1480+
let responseContent = JSON.stringify(newResponse, null, 2)
1481+
if (typeof newResponse.content === 'string') {
1482+
responseContent = newResponse.content
1483+
}
1484+
sseStreamer.streamTokenEvent(chatId, responseContent)
14771485
}
14781486
}
14791487

@@ -1715,7 +1723,11 @@ class Agent_Agentflow implements INode {
17151723

17161724
// Stream non-streaming response if this is the last node
17171725
if (isLastNode && sseStreamer) {
1718-
sseStreamer.streamTokenEvent(chatId, JSON.stringify(newResponse, null, 2))
1726+
let responseContent = JSON.stringify(newResponse, null, 2)
1727+
if (typeof newResponse.content === 'string') {
1728+
responseContent = newResponse.content
1729+
}
1730+
sseStreamer.streamTokenEvent(chatId, responseContent)
17191731
}
17201732
}
17211733

packages/components/nodes/agentflow/LLM/LLM.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,11 @@ class LLM_Agentflow implements INode {
460460
// Stream whole response back to UI if this is the last node
461461
if (isLastNode && options.sseStreamer) {
462462
const sseStreamer: IServerSideEventStreamer = options.sseStreamer as IServerSideEventStreamer
463-
sseStreamer.streamTokenEvent(chatId, JSON.stringify(response, null, 2))
463+
let responseContent = JSON.stringify(response, null, 2)
464+
if (typeof response.content === 'string') {
465+
responseContent = response.content
466+
}
467+
sseStreamer.streamTokenEvent(chatId, responseContent)
464468
}
465469
}
466470

0 commit comments

Comments
 (0)