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 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 { | ||||||
|  |       if (!conversation.model) { | ||||||
|  |         conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]; | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|   updatedHistory.forEach((conversation) => { |       if (!conversation.prompt) { | ||||||
|     if (!conversation.model) { |         conversation.prompt = DEFAULT_SYSTEM_PROMPT; | ||||||
|       conversation.model = OpenAIModels[OpenAIModelID.GPT_3_5]; |       } | ||||||
|  | 
 | ||||||
|  |       if (!conversation.folderId) { | ||||||
|  |         conversation.folderId = 0; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       acc.push(conversation); | ||||||
|  |       return acc; | ||||||
|  |     } catch (error) { | ||||||
|  |       console.warn(`error while cleaning conversations' history. Removing culprit`, error); | ||||||
|     } |     } | ||||||
| 
 |     return acc; | ||||||
|     if (!conversation.prompt) { |   }, []); | ||||||
|       conversation.prompt = DEFAULT_SYSTEM_PROMPT; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     if (!conversation.folderId) { |  | ||||||
|       conversation.folderId = 0; |  | ||||||
|     } |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   return updatedHistory; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue