典籍知识问答重新生成和消息修改Bug修改

1.Bug:

{messageId: "temp-user-1747051925999",...} messageId : "temp-user-1747051925999" newContent : "关于选中的内容:\"The ancient people lived long by following natural laws\",我的问题是:翻译成法文是什么意思\n" 负载是这个

{ "timestamp": "2025-05-12T12:17:39.268+00:00", "status": 400, "error": "Bad Request", "path": "/api/qa/stream-edit" } 响应是这个

2.错误原因

用户消息的ID在创建时是临时的,但在流式响应中未正确更新为持久化ID。

3.修改代码

// 修改流式响应处理部分

while (true) {

const { done, value } = await reader.read();

if (done) break;

buffer += decoder.decode(value, { stream: true });

const lines = buffer.split('\n');

buffer = lines.pop() || '';

for (const line of lines) {

// 捕获持久化ID事件

if (line.startsWith('event: START')) {

const persistedId = line.replace('event: START\ndata:', '').trim();

// 更新临时消息ID

const tempMsg = currentMessages.value.find(m => m.id === aiMsg.id);

if (tempMsg) {

tempMsg.id = persistedId; // 更新为真实ID

tempMsg.temp = false; // 移除临时标记

currentMessages.value = [...currentMessages.value]; // 触发响应式更新

}

}

// 原有内容

}

}

// 修改编辑消息方法

const saveEdit = async (msgId) => {

if (isSavingEdit.value) return;

// 新增ID有效性检查

if (msgId.startsWith('temp-')) {

alert('请等待消息生成完成后再操作');

return;

}

isSavingEdit.value = true;

try {

await qastore.editMessage(msgId, editingStates.value[msgId].editedContent);

editingStates.value[msgId].editing = false;

} finally {

isSavingEdit.value = false;

}

}

//原有内容

相关推荐
前端付豪1 分钟前
揭秘网易统一日志采集与故障定位平台揭秘:如何在亿级请求中1分钟定位线上异常
前端·后端·架构
香蕉可乐荷包蛋12 分钟前
vue对axios的封装和使用
前端·javascript·vue.js·axios
娃哈哈哈哈呀15 分钟前
html - <mark>标签
前端·html
QQ_hoverer16 分钟前
前端使用 preview 插件预览docx文件
前端·javascript·layui·jquery
陈随易18 分钟前
Lodash 杀手来了!es-toolkit v1.39.0 已完全兼容4年未更新的 Lodash
前端·后端·程序员
Thomas游戏开发24 分钟前
Unity3D TextMeshPro终极使用指南
前端·unity3d·游戏开发
potender25 分钟前
前端基础学习html+css+js
前端·css·学习·html·js
Hilaku34 分钟前
你以为的 Tailwind 并不高效,看看这些使用误区
前端·css·前端框架
帅夫帅夫36 分钟前
Vibe Coding从零开始教你打造一个WebLLM页面
前端·人工智能
Vonalien36 分钟前
Trae 深度体验:从怀疑到真香,AI 如何重塑我的开发流?
前端