recover from corrupted conversationHistory data (#162)

If an item from conversationHistory is badly corrupted, skip it instead of crashing the app
This commit is contained in:
Thomas LÉVEIL 2023-03-25 21:10:17 +01:00 committed by GitHub
parent 1253565a69
commit 0038bb8366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -39,9 +39,8 @@ export const cleanConversationHistory = (history: Conversation[]) => {
// added system prompt for each conversation (3/21/23) // added system prompt for each conversation (3/21/23)
// added folders (3/23/23) // added folders (3/23/23)
let updatedHistory = [...history]; return history.reduce((acc: Conversation[], conversation) => {
try {
updatedHistory.forEach((conversation) => {
if (!conversation.model) { if (!conversation.model) {
conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]; conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5];
} }
@ -53,7 +52,12 @@ export const cleanConversationHistory = (history: Conversation[]) => {
if (!conversation.folderId) { if (!conversation.folderId) {
conversation.folderId = 0; conversation.folderId = 0;
} }
});
return updatedHistory; acc.push(conversation);
return acc;
} catch (error) {
console.warn(`error while cleaning conversations' history. Removing culprit`, error);
}
return acc;
}, []);
}; };