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:
parent
1253565a69
commit
0038bb8366
|
@ -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;
|
||||
}, []);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue