fix: model markdown parse failed

This commit is contained in:
jialin
2024-11-22 11:55:19 +08:00
parent 67febd3e25
commit c8c22b3f22
15 changed files with 514 additions and 50 deletions
+3 -7
View File
@@ -128,12 +128,8 @@ export const cosineSimilarity = (vec1: number[], vec2: number[]) => {
return dotProduct / (magnitudeA * magnitudeB);
};
const htmlSpecialTags = /^<html>(.|\n|\r)*<\/html>$/i;
export const isHTMLDocumentString = (str: string) => {
try {
const parser = new DOMParser();
const doc = parser.parseFromString(str, 'text/html');
return doc.documentElement.tagName.toLowerCase() === 'html';
} catch (e) {
return false;
}
return htmlSpecialTags.test(str?.trim());
};