|
|
@ -596,6 +596,7 @@ async function sendChatHandle(event) { |
|
|
function sendChatMessage(data){ |
|
|
function sendChatMessage(data){ |
|
|
controller.value = new AbortController() |
|
|
controller.value = new AbortController() |
|
|
postChatMessage(data,{signal:controller.value.signal}).then(res=>{ |
|
|
postChatMessage(data,{signal:controller.value.signal}).then(res=>{ |
|
|
|
|
|
console.log(res) |
|
|
if (res.status !== 200){ |
|
|
if (res.status !== 200){ |
|
|
// chatList.value.push({"chatId":uuidv4(),"type":"answer","content":[{"type":"text","content":"服务异常,错误码:"+res.status}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":'',"thumbDownReason":''}) |
|
|
// chatList.value.push({"chatId":uuidv4(),"type":"answer","content":[{"type":"text","content":"服务异常,错误码:"+res.status}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":'',"thumbDownReason":''}) |
|
|
currentError.value = "服务异常,错误码:"+res.status +",请联系管理员!" |
|
|
currentError.value = "服务异常,错误码:"+res.status +",请联系管理员!" |
|
|
@ -713,44 +714,51 @@ const getWrite = (reader) => { |
|
|
const processChunk = (chunk) => { |
|
|
const processChunk = (chunk) => { |
|
|
currentJobId.value = chunk.job_id; |
|
|
currentJobId.value = chunk.job_id; |
|
|
const lastMsg = chatList.value[chatList.value.length - 1]; |
|
|
const lastMsg = chatList.value[chatList.value.length - 1]; |
|
|
// 修复点5:统一处理所有类型的数据块 |
|
|
if (chunk.type && chunk.type=== 'error'){ |
|
|
if (chunk.docs?.length) { |
|
|
lastMsg.content.push({content: "服务异常,请联系管理员!", type: "text"}) |
|
|
lastMsg.content.push({ content: chunk.docs, type: "docs" }); |
|
|
|
|
|
} else if (chunk.G6_ER?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.G6_ER, type: "G6_ER" }); |
|
|
|
|
|
} else if (chunk.html_image?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.html_image, type: "html_image" }); |
|
|
|
|
|
} else if (chunk.table?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.table, type: "table" }); |
|
|
|
|
|
} else if (chunk.router) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.router, type: "router" }); |
|
|
|
|
|
} else if (chunk.choices?.length) { |
|
|
|
|
|
// 修复点6:纯文本处理增加防重复校验 |
|
|
|
|
|
// const text = chunk.choices[0].delta.content.replace(/\n/g, "\n\n"); |
|
|
|
|
|
// 智能换行处理 |
|
|
|
|
|
const text = chunk.choices[0].delta.content; |
|
|
|
|
|
// const isNewParagraph = content.startsWith('\n\n'); |
|
|
|
|
|
// 仅当需要时添加换行 |
|
|
|
|
|
// const text = content; |
|
|
|
|
|
// const text = isNewParagraph |
|
|
|
|
|
// ? content.replace(/\n{2,}/g, '\n\n') |
|
|
|
|
|
// : content.replace(/\n/g, '\n\n'); |
|
|
|
|
|
const lastContent = lastMsg.content[lastMsg.content.length - 1]; |
|
|
|
|
|
if (lastContent?.type === "text") { |
|
|
|
|
|
lastContent.content += text; |
|
|
|
|
|
} else { |
|
|
|
|
|
lastMsg.content.push({ content: text, type: "text" }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (chunk.interrupt){ |
|
|
|
|
|
lastMsg.interrupt = chunk.interrupt |
|
|
|
|
|
} |
|
|
|
|
|
// 修复点7:统一处理结束标志 |
|
|
|
|
|
if (chunk.checkpointer) { |
|
|
|
|
|
lastMsg.checkpointer = chunk.checkpointer |
|
|
|
|
|
currentJobId.value = '' |
|
|
currentJobId.value = '' |
|
|
lastMsg.isEnd = true; |
|
|
lastMsg.isEnd = true; |
|
|
lastMsg.time = formatDate(new Date()); |
|
|
lastMsg.time = formatDate(new Date()); |
|
|
|
|
|
}else { |
|
|
|
|
|
// 修复点5:统一处理所有类型的数据块 |
|
|
|
|
|
if (chunk.docs?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.docs, type: "docs" }); |
|
|
|
|
|
} else if (chunk.G6_ER?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.G6_ER, type: "G6_ER" }); |
|
|
|
|
|
} else if (chunk.html_image?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.html_image, type: "html_image" }); |
|
|
|
|
|
} else if (chunk.table?.length) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.table, type: "table" }); |
|
|
|
|
|
} else if (chunk.router) { |
|
|
|
|
|
lastMsg.content.push({ content: chunk.router, type: "router" }); |
|
|
|
|
|
} else if (chunk.choices?.length) { |
|
|
|
|
|
// 修复点6:纯文本处理增加防重复校验 |
|
|
|
|
|
// const text = chunk.choices[0].delta.content.replace(/\n/g, "\n\n"); |
|
|
|
|
|
// 智能换行处理 |
|
|
|
|
|
const text = chunk.choices[0].delta.content; |
|
|
|
|
|
// const isNewParagraph = content.startsWith('\n\n'); |
|
|
|
|
|
// 仅当需要时添加换行 |
|
|
|
|
|
// const text = content; |
|
|
|
|
|
// const text = isNewParagraph |
|
|
|
|
|
// ? content.replace(/\n{2,}/g, '\n\n') |
|
|
|
|
|
// : content.replace(/\n/g, '\n\n'); |
|
|
|
|
|
const lastContent = lastMsg.content[lastMsg.content.length - 1]; |
|
|
|
|
|
if (lastContent?.type === "text") { |
|
|
|
|
|
lastContent.content += text; |
|
|
|
|
|
} else { |
|
|
|
|
|
lastMsg.content.push({ content: text, type: "text" }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (chunk.interrupt){ |
|
|
|
|
|
lastMsg.interrupt = chunk.interrupt |
|
|
|
|
|
} |
|
|
|
|
|
// 修复点7:统一处理结束标志 |
|
|
|
|
|
if (chunk.checkpointer) { |
|
|
|
|
|
lastMsg.checkpointer = chunk.checkpointer |
|
|
|
|
|
currentJobId.value = '' |
|
|
|
|
|
lastMsg.isEnd = true; |
|
|
|
|
|
lastMsg.time = formatDate(new Date()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
nextTick(() => scrollDiv.value.setScrollTop(getMaxHeight())); |
|
|
nextTick(() => scrollDiv.value.setScrollTop(getMaxHeight())); |
|
|
}; |
|
|
}; |
|
|
|