Browse Source

连接大模型失败时的返回

master
xueyinfei 3 weeks ago
parent
commit
cdb4a76e8b
  1. 78
      vue-fastapi-frontend/src/views/aichat/aichat.vue

78
vue-fastapi-frontend/src/views/aichat/aichat.vue

@ -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()));
}; };

Loading…
Cancel
Save