Skip to content

Commit 138c87c

Browse files
authored
webui : fix handling incomplete chunks (#16107)
1 parent c6db9a1 commit 138c87c

File tree

1 file changed

+3
-1
lines changed
  • tools/server/webui/src/lib/services

1 file changed

+3
-1
lines changed

tools/server/webui/src/lib/services/chat.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ export class ChatService {
264264
let lastTimings: ChatMessageTimings | undefined;
265265

266266
try {
267+
let chunk = '';
267268
while (true) {
268269
const { done, value } = await reader.read();
269270
if (done) break;
270271

271-
const chunk = decoder.decode(value, { stream: true });
272+
chunk += decoder.decode(value, { stream: true });
272273
const lines = chunk.split('\n');
274+
chunk = lines.pop() || ''; // Save incomplete line for next read
273275

274276
for (const line of lines) {
275277
if (line.startsWith('data: ')) {

0 commit comments

Comments
 (0)