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

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MrlolDev committed Dec 16, 2023
1 parent e8621a1 commit 468d7dc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/bot/utils/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ export async function getConversation(userId: string, modelName: string) {
await update("conversations", conversation.id, updatedConversation);
conversation.history.messages = [];
}
// check if order is user, model, user, model, etc
// if not, reset conversation
let lastRole = "user";
for (const message of conversation.history.messages) {
if (message.role === lastRole) {
const updatedConversation = {
history: {
datasetId: conversation.history.datasetId,
messages: [],
},
last_update: Date.now(),
};
await update("conversations", conversation.id, updatedConversation);
conversation.history.messages = [];
break;
}
lastRole = message.role;
}

return conversation;
}

Expand Down

0 comments on commit 468d7dc

Please sign in to comment.