From 7fa823447fac328ce3871741d12e9d4faec09e30 Mon Sep 17 00:00:00 2001 From: code-october <148516338+code-october@users.noreply.github.com> Date: Thu, 3 Oct 2024 02:16:49 +0000 Subject: [PATCH] add more criteria for detecting invalid messages --- app/store/chat.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/store/chat.ts b/app/store/chat.ts index 968d8cb64..7ea0d2d61 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -693,6 +693,17 @@ export const useChatStore = createPersistStore( } function isValidMessage(message: any): boolean { + if (message.startsWith("```") && message.endsWith("```")) { + const jsonString = message.slice(3, -3).trim(); + try { + const jsonObject = JSON.parse(jsonString); + if (jsonObject.error) { + return false; + } + } catch (e) { + console.log("Invalid JSON format."); + } + } return typeof message === "string" && !message.startsWith("```json"); } },