mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-17 14:33:41 +08:00
add more criteria for detecting invalid messages
This commit is contained in:
@@ -693,6 +693,17 @@ export const useChatStore = createPersistStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isValidMessage(message: any): boolean {
|
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");
|
return typeof message === "string" && !message.startsWith("```json");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user