fix:对话时只提供最近6条记录

This commit is contained in:
Gsh
2025-07-02 00:11:43 +08:00
parent b020f48325
commit 1200d02fbf
2 changed files with 14 additions and 3 deletions

View File

@@ -82,6 +82,7 @@ watch(
if (v) {
// 发送消息
console.log('发送消息 v', v);
console.log('发送消息--error', bubbleItems);
setTimeout(() => {
startSSE(v);
}, 350);
@@ -167,12 +168,21 @@ async function startSSE(chatContent: string) {
// 这里有必要调用一下 BubbleList 组件的滚动到底部 手动触发 自动滚动
bubbleListRef.value?.scrollToBottom();
console.log('bubbleItems.value--', bubbleItems.value);
for await (const chunk of stream({
// messages: bubbleItems.value
// .filter((item: any) => item.role === 'user')
// .map((item: any) => ({
// role: item.role,
// content: item.content,
// })),
messages: bubbleItems.value
.filter((item: any) => item.role === 'user')
.map((item: any) => ({
.slice(-6) // 直接取最后6条记录最近的
.map((item: MessageItem) => ({
role: item.role,
content: item.content,
content: (item.role === 'ai' || item.role === 'system') && item.content.length > 2000
? `${item.content.substring(0, 2000)}...(内容过长,已省略)`
: item.content,
})),
sessionId: route.params?.id !== 'not_login' ? String(route.params?.id) : undefined,
userId: userStore.userInfo?.userId,

View File

@@ -120,6 +120,7 @@ function jwtPlugin(): {
if (error.status === 403) {
// 弹窗提示
ElMessage.error('业务错误,请稍后再试');
console.error('Fetch error:', error);
}
},
};