|
|
@ -494,7 +494,6 @@ const getWrite = (reader) => { |
|
|
if (done) return; |
|
|
if (done) return; |
|
|
const decoder = new TextDecoder('utf-8'); |
|
|
const decoder = new TextDecoder('utf-8'); |
|
|
let str = decoder.decode(value, { stream: true }); |
|
|
let str = decoder.decode(value, { stream: true }); |
|
|
console.log(str) |
|
|
|
|
|
tempResult += str; |
|
|
tempResult += str; |
|
|
|
|
|
|
|
|
// 修复点2:使用非贪婪匹配确保精确分块 |
|
|
// 修复点2:使用非贪婪匹配确保精确分块 |
|
|
@ -524,7 +523,7 @@ const getWrite = (reader) => { |
|
|
|
|
|
|
|
|
const processChunk = (chunk) => { |
|
|
const processChunk = (chunk) => { |
|
|
const lastMsg = chatList.value[chatList.value.length - 1]; |
|
|
const lastMsg = chatList.value[chatList.value.length - 1]; |
|
|
|
|
|
console.log(chunk) |
|
|
// 修复点5:统一处理所有类型的数据块 |
|
|
// 修复点5:统一处理所有类型的数据块 |
|
|
if (chunk.docs?.length) { |
|
|
if (chunk.docs?.length) { |
|
|
lastMsg.content.push({ content: chunk.docs, type: "docs" }); |
|
|
lastMsg.content.push({ content: chunk.docs, type: "docs" }); |
|
|
@ -534,7 +533,7 @@ const getWrite = (reader) => { |
|
|
lastMsg.content.push({ content: chunk.html_image, type: "html_image" }); |
|
|
lastMsg.content.push({ content: chunk.html_image, type: "html_image" }); |
|
|
} else if (chunk.table?.length) { |
|
|
} else if (chunk.table?.length) { |
|
|
lastMsg.content.push({ content: chunk.table, type: "table" }); |
|
|
lastMsg.content.push({ content: chunk.table, type: "table" }); |
|
|
} else if (chunk.router?.length) { |
|
|
} else if (chunk.router) { |
|
|
lastMsg.content.push({ content: chunk.router, type: "router" }); |
|
|
lastMsg.content.push({ content: chunk.router, type: "router" }); |
|
|
} else if (chunk.choices?.length) { |
|
|
} else if (chunk.choices?.length) { |
|
|
// 修复点6:纯文本处理增加防重复校验 |
|
|
// 修复点6:纯文本处理增加防重复校验 |
|
|
@ -547,7 +546,6 @@ const getWrite = (reader) => { |
|
|
? content.replace(/\n{2,}/g, '\n\n') |
|
|
? content.replace(/\n{2,}/g, '\n\n') |
|
|
: content.replace(/\n/g, ' '); |
|
|
: content.replace(/\n/g, ' '); |
|
|
const lastContent = lastMsg.content[lastMsg.content.length - 1]; |
|
|
const lastContent = lastMsg.content[lastMsg.content.length - 1]; |
|
|
console.log(lastContent) |
|
|
|
|
|
if (lastContent?.type === "text") { |
|
|
if (lastContent?.type === "text") { |
|
|
lastContent.content += text; |
|
|
lastContent.content += text; |
|
|
} else { |
|
|
} else { |
|
|
@ -558,7 +556,6 @@ const getWrite = (reader) => { |
|
|
// 修复点7:统一处理结束标志 |
|
|
// 修复点7:统一处理结束标志 |
|
|
if (chunk.isEnd || chunk.is_end) { |
|
|
if (chunk.isEnd || chunk.is_end) { |
|
|
lastMsg.isEnd = true; |
|
|
lastMsg.isEnd = true; |
|
|
console.log(lastMsg) |
|
|
|
|
|
lastMsg.time = formatDate(new Date()); |
|
|
lastMsg.time = formatDate(new Date()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|