webui : fix handling incomplete chunks (#16107)
This commit is contained in:
parent
c6db9a1027
commit
138c87ce8b
|
|
@ -264,12 +264,14 @@ export class ChatService {
|
||||||
let lastTimings: ChatMessageTimings | undefined;
|
let lastTimings: ChatMessageTimings | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let chunk = '';
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
if (done) break;
|
if (done) break;
|
||||||
|
|
||||||
const chunk = decoder.decode(value, { stream: true });
|
chunk += decoder.decode(value, { stream: true });
|
||||||
const lines = chunk.split('\n');
|
const lines = chunk.split('\n');
|
||||||
|
chunk = lines.pop() || ''; // Save incomplete line for next read
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (line.startsWith('data: ')) {
|
if (line.startsWith('data: ')) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue