mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-05-28 20:50:00 +02:00
parent
0460531c72
commit
62302e3faf
@ -60,17 +60,25 @@ export function extractCodeText(
|
||||
return codeText || "";
|
||||
}
|
||||
|
||||
// This is a temporary solution to preprocess LaTeX in LLM output
|
||||
// We must preprocess LaTeX in the LLM output to avoid improper formatting
|
||||
export const preprocessLaTeX = (content: string) => {
|
||||
// Replace block-level LaTeX delimiters \[ \] with $$ $$
|
||||
const blockProcessedContent = content.replace(
|
||||
// 1) Escape dollar signs used outside of LaTeX context
|
||||
const escapedCurrencyContent = content.replace(
|
||||
/\$(\d+(?:\.\d*)?)/g,
|
||||
(_, p1) => `\\$${p1}`
|
||||
);
|
||||
|
||||
// 2) Replace block-level LaTeX delimiters \[ \] with $$ $$
|
||||
const blockProcessedContent = escapedCurrencyContent.replace(
|
||||
/\\\[([\s\S]*?)\\\]/g,
|
||||
(_, equation) => `$$${equation}$$`
|
||||
);
|
||||
// Replace inline LaTeX delimiters \( \) with $ $
|
||||
|
||||
// 3) Replace inline LaTeX delimiters \( \) with $ $
|
||||
const inlineProcessedContent = blockProcessedContent.replace(
|
||||
/\\\(([\s\S]*?)\\\)/g,
|
||||
(_, equation) => `$${equation}$`
|
||||
);
|
||||
|
||||
return inlineProcessedContent;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user