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

}

}

//原有内容

相关推荐
u0111026757 分钟前
WebP 转成 PNG 后为什么更大?图片格式转换不等于压缩
前端·javascript·vue.js
万少7 分钟前
Qoder sonus模型 20分钟,复刻 马斯克 飞天汽车
前端·后端·算法
java1234_小锋29 分钟前
【技术专题】HTML5 网页技术 - HTML5 列表标签
前端·html·html5
强二小哥帅31 分钟前
Kotlin 协程复习笔记
前端
不可能片场34 分钟前
工程实践 原子替换改了 ctime 怎么修
前端·electron
暧暧内含光34 分钟前
HTTP 文件传输体系全解:从协议标头、OSS 架构到流媒体分片
前端
静默回滚36 分钟前
浏览器能显示AVIF,却导不出一张AVIF
前端
小皮虾41 分钟前
小程序全局状态还能这么简单?只需初始化一次,页面自动同步
前端·javascript·微信小程序
用户8186180280044 分钟前
RESTful API 设计规范与版本演进
前端
补码缩写1 小时前
前端AVIF编码开多线程快两三倍,speed调到8就不快了
前端