From a36ab65bd2d9d8a89659d60b51b30babb3d4148c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 15 May 2023 15:11:15 +0800 Subject: [PATCH] refactor(ai): add message summart limit --- .../com.msgbyte.ai-assistant/src/popover.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/web/plugins/com.msgbyte.ai-assistant/src/popover.tsx b/client/web/plugins/com.msgbyte.ai-assistant/src/popover.tsx index 61690e33..4ec5b512 100644 --- a/client/web/plugins/com.msgbyte.ai-assistant/src/popover.tsx +++ b/client/web/plugins/com.msgbyte.ai-assistant/src/popover.tsx @@ -142,16 +142,18 @@ export const AssistantPopover: React.FC<{ onClick={async () => { const plainMessages = ( await Promise.all( - messages.map( - async (item) => - `${ - ( - await getCachedUserInfo(item.author) - ).nickname - }: ${getMessageTextDecorators().serialize( - item.content ?? '' - )}` - ) + messages + .slice(0, 30) // get first 30 message, too much will throw error + .map( + async (item) => + `${ + ( + await getCachedUserInfo(item.author) + ).nickname + }: ${getMessageTextDecorators().serialize( + item.content ?? '' + )}` + ) ) ).join('\n');