Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
fix: use last 10 messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MrlolDev committed Dec 23, 2023
1 parent d6eeab0 commit c748627
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/bot/utils/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ export async function getConversation(userId: string, modelName: string) {
}
lastRole = message.role;
}
// if there is more than 10 messages, use the last 10
if (conversation.history.messages.length > 10) {
const updatedConversation = {
history: {
datasetId: conversation.history.datasetId,
messages: conversation.history.messages.slice(-10),
},
last_update: Date.now(),
};
await update("conversations", conversation.id, updatedConversation);
conversation.history.messages = conversation.history.messages.slice(-10);
conversation.history.messages = conversation.history.messages.slice(-10);
// get the last 10 messages
}


return conversation;
}
Expand Down

0 comments on commit c748627

Please sign in to comment.