diff --git a/utils/app/clean.ts b/utils/app/clean.ts index e07780f..7ae2755 100644 --- a/utils/app/clean.ts +++ b/utils/app/clean.ts @@ -39,21 +39,25 @@ export const cleanConversationHistory = (history: Conversation[]) => { // added system prompt for each conversation (3/21/23) // added folders (3/23/23) - let updatedHistory = [...history]; + return history.reduce((acc: Conversation[], conversation) => { + try { + if (!conversation.model) { + conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]; + } - updatedHistory.forEach((conversation) => { - if (!conversation.model) { - conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]; + if (!conversation.prompt) { + conversation.prompt = DEFAULT_SYSTEM_PROMPT; + } + + if (!conversation.folderId) { + conversation.folderId = 0; + } + + acc.push(conversation); + return acc; + } catch (error) { + console.warn(`error while cleaning conversations' history. Removing culprit`, error); } - - if (!conversation.prompt) { - conversation.prompt = DEFAULT_SYSTEM_PROMPT; - } - - if (!conversation.folderId) { - conversation.folderId = 0; - } - }); - - return updatedHistory; + return acc; + }, []); };