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

editingStates.valuemsgId.editing = false;

} finally {

isSavingEdit.value = false;

}

}

//原有内容

相关推荐
xiaofeichaichai2 小时前
Webpack
前端·webpack·node.js
问心无愧05132 小时前
ctf show web入门111
android·前端·笔记
唐某人丶3 小时前
模型越来越强,我们还需要 Agent 工程吗?—— 从价值重估到 Harness 实践
前端·agent·ai编程
智码看视界3 小时前
现代Web开发基础:全栈工程师的起航点
前端·后端·c5全栈
JS菌3 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现
前端·人工智能·后端
excel4 小时前
HLS TS 文件损坏的元凶:Git 提交与拉取
前端
Aphasia3114 小时前
https连接传输流程
前端·面试
徐小夕4 小时前
万字长文!千万级文档 RAG 知识库系统落地实践
前端·算法·github
threelab5 小时前
Three.js 物理模拟着色器 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器