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

}

}

//原有内容

相关推荐
qq_433502186 分钟前
Codex cli 飞书文档创建进阶实用命令 + Skill 创建&使用 小白完整教程
java·前端·飞书
IT_陈寒12 分钟前
为什么我的Vite热更新老是重新加载整个页面?
前端·人工智能·后端
一袋米扛几楼9831 分钟前
【网络安全】SIEM -Security Information and Event Management 工具是什么?
前端·安全·web安全
小陈工42 分钟前
2026年4月7日技术资讯洞察:下一代数据库融合、AI基础设施竞赛与异步编程实战
开发语言·前端·数据库·人工智能·python
Cobyte1 小时前
3.响应式系统基础:从发布订阅模式的角度理解 Vue2 的数据响应式原理
前端·javascript·vue.js
竹林8181 小时前
从零到一:在React前端中集成The Graph查询Uniswap V3池数据实战
前端·javascript
Mintopia1 小时前
别再迷信"优化":大多数性能问题根本不在代码里
前端
倾颜1 小时前
接入 MCP,不一定要先平台化:一次 AI Runtime 的实战取舍
前端·后端·mcp
军军君011 小时前
Three.js基础功能学习十八:智能黑板实现实例五
前端·javascript·vue.js·3d·typescript·前端框架·threejs