Extracting the traversal.

This commit is contained in:
Yu QX committed 2025-05-26 21:04:08 +08:00
1 parent b9f74a66b2
commit bb62bd9c1f
1 file changed
+13 -12
+13 -12
View File
@@ -91,15 +91,19 @@ export const sanitizeResponseContent = (content: string) => {
export const processResponseContent = (content: string) => {
// This function is used to process the response content before the response content is rendered.
content = processChineseContent(content);
return content.trim();
};
function processChineseContent(content: string): string {
// Tackle "Model output issue not following the standard Markdown/LaTeX format" in Chinese.
const lines = content.split('\n');
const processedLines = lines.map((line) => {
if (/[\u4e00-\u9fa5]/.test(line)) {
line = processChineseContent(line);
}
return line;
});
content = processedLines.join('\n');
return content.trim();
};
// Tackle "Model output issue not following the standard Markdown/LaTeX format" in Chinese.
function processChineseContent(line: string): string {
// Problems caused by Chinese parentheses
/* Discription:
* When `*` has Chinese parentheses on the inside, markdown parser ignore bold or italic style.
@@ -115,14 +119,11 @@ function processChineseContent(content: string): string {
*/
if (line.includes('*')) {
// Handle **bold** with Chinese parentheses
line = processChineseContent_ParenthesesRelated(line, '**', '(', ')');
line = processChineseParentheses(line, '**', '(', ')');
// Handle *italic* with Chinese parentheses
line = processChineseContent_ParenthesesRelated(line, '*', '(', ')');
}
line = processChineseParentheses(line, '*', '(', ')');
}
return line;
});
return processedLines.join('\n');
}
function isChineseChar(char: string): boolean {
@@ -130,7 +131,7 @@ function isChineseChar(char: string): boolean {
}
// Helper function for `processChineseContent`
function processChineseContent_ParenthesesRelated(
function processChineseParentheses(
line: string,
symbol: string,
leftSymbol: string,