From fa6cd6d6a6b45f1089523df6e53afa5da774054d Mon Sep 17 00:00:00 2001 From: Vinlic Date: Mon, 1 Apr 2024 23:30:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B5=81=E4=BC=A0=E8=BE=93?= =?UTF-8?q?=E6=97=B6=E5=88=86=E5=8C=85=E5=AF=BC=E8=87=B4=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/chat.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/controllers/chat.ts b/src/api/controllers/chat.ts index 9cce9e7..b19af87 100644 --- a/src/api/controllers/chat.ts +++ b/src/api/controllers/chat.ts @@ -479,12 +479,21 @@ async function receiveStream(model: string, convId: string, stream: any) { : ""; } }; + let temp = Buffer.from([]); // 将流数据传到转换器,每个buffer去除数据头5字节 stream.on("data", (buffer: Buffer) => { const parts: Buffer[] = []; let length = 0; let sizeLength = 0; let i = 0; + if(buffer[buffer.length - 1] != 125) { + temp = Buffer.concat([temp, buffer]); + return; + } + else if(temp.length > 0) { + buffer = Buffer.concat([temp, buffer]); + temp = Buffer.from([]); + } for (i = 0; i < buffer.byteLength; i++) { const byte = buffer.readUInt8(i); if (byte == 0x00 || byte == 0x02) {