典籍知识问答重新生成和消息修改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;

}

}

//原有内容

相关推荐
xiaopengbc2 分钟前
在Webpack中,如何在不同环境中使用不同的API地址?
前端·webpack·node.js
前端AK君7 分钟前
React中台系统如何嵌入到业务系统中
前端
Slice_cy8 分钟前
不定高虚拟列表
前端
前端AK君17 分钟前
React组件库如何在vue项目中使用
前端
Moonbit27 分钟前
MoonBit 再次走进清华:张宏波受邀参加「思源计划」与「程序设计训练课」
前端·后端·编程语言
RestCloud30 分钟前
一站式数据集成:iPaaS 如何让开发者和业务人员都满意?
前端·后端·架构
li357440 分钟前
React 核心 Hook 与冷门技巧:useReducer、useEffect、useRef 及 is 属性全解析
前端·javascript·react.js
菜市口的跳脚长颌44 分钟前
Web3 基础
前端
快乐是Happy44 分钟前
分享一个非常实用的防止重复提交操作
前端·javascript
王蛋1111 小时前
前端工作问题或知识记录
前端·npm·node.js