修复对话断断续续的问题,锁定在 fastapi 上
This commit is contained in:
parent
f0984191ae
commit
601034e739
@ -434,31 +434,47 @@ const fetchChatResponse = (user_input, cur_res_id) => {
|
|||||||
groupRefs(cur_res_id);
|
groupRefs(cur_res_id);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
groupRefs(cur_res_id);
|
updateMessage({
|
||||||
|
id: cur_res_id,
|
||||||
|
status: "finished",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
isStreaming.value = false;
|
isStreaming.value = false;
|
||||||
if (conv.value.messages.length === 2) { renameTitle(); }
|
if (conv.value.messages.length === 2) { renameTitle(); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunk = decoder.decode(value, { stream: true });
|
buffer += decoder.decode(value, { stream: true });
|
||||||
buffer += chunk;
|
const lines = buffer.split('\n');
|
||||||
try {
|
|
||||||
const data = JSON.parse(chunk);
|
// 处理除最后一行外的所有完整行
|
||||||
updateMessage({
|
for (let i = 0; i < lines.length - 1; i++) {
|
||||||
id: cur_res_id,
|
const line = lines[i].trim();
|
||||||
text: data.response,
|
if (line) {
|
||||||
model_name: data.model_name,
|
try {
|
||||||
status: data.status,
|
const data = JSON.parse(line);
|
||||||
meta: data.meta,
|
updateMessage({
|
||||||
});
|
id: cur_res_id,
|
||||||
console.debug(data.response)
|
text: data.response,
|
||||||
if (data.history) {
|
model_name: data.model_name,
|
||||||
conv.value.history = data.history;
|
status: data.status,
|
||||||
|
meta: data.meta,
|
||||||
|
});
|
||||||
|
// console.log("Last message", conv.value.messages[conv.value.messages.length - 1].text)
|
||||||
|
// console.log("Last message", conv.value.messages[conv.value.messages.length - 1].status)
|
||||||
|
|
||||||
|
if (data.history) {
|
||||||
|
conv.value.history = data.history;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('JSON 解析错误:', e, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
// console.debug('JSON 解析错误:', e, chunk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保留最后一个可能不完整的行
|
||||||
|
buffer = lines[lines.length - 1];
|
||||||
|
|
||||||
return readChunk(); // 继续读取
|
return readChunk(); // 继续读取
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -471,7 +487,7 @@ const fetchChatResponse = (user_input, cur_res_id) => {
|
|||||||
status: "error",
|
status: "error",
|
||||||
});
|
});
|
||||||
isStreaming.value = false;
|
isStreaming.value = false;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchRefs = (cur_res_id) => {
|
const fetchRefs = (cur_res_id) => {
|
||||||
@ -975,3 +991,4 @@ watch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user