mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-01 18:10:39 +02:00
validate messages (#2139)
This commit is contained in:
@@ -154,10 +154,17 @@ export const AIMessage = ({
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeBlockRegex = /```[\s\S]*?```|```[\s\S]*?$/g;
|
const codeBlockRegex = /```(\w*)\n[\s\S]*?```|```[\s\S]*?$/g;
|
||||||
const matches = content.match(codeBlockRegex);
|
const matches = content.match(codeBlockRegex);
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
|
content = matches.reduce((acc, match) => {
|
||||||
|
if (!match.match(/```\w+/)) {
|
||||||
|
return acc.replace(match, match.replace("```", "```plaintext"));
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, content);
|
||||||
|
|
||||||
const lastMatch = matches[matches.length - 1];
|
const lastMatch = matches[matches.length - 1];
|
||||||
if (!lastMatch.endsWith("```")) {
|
if (!lastMatch.endsWith("```")) {
|
||||||
return content;
|
return content;
|
||||||
@@ -166,7 +173,6 @@ export const AIMessage = ({
|
|||||||
|
|
||||||
return content + (!isComplete && !toolCallGenerating ? " [*]() " : "");
|
return content + (!isComplete && !toolCallGenerating ? " [*]() " : "");
|
||||||
};
|
};
|
||||||
|
|
||||||
const finalContent = processContent(content as string);
|
const finalContent = processContent(content as string);
|
||||||
|
|
||||||
const { isHovering, trackedElementRef, hoverElementRef } = useMouseTracking();
|
const { isHovering, trackedElementRef, hoverElementRef } = useMouseTracking();
|
||||||
@@ -400,7 +406,6 @@ export const AIMessage = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
code: (props) => (
|
code: (props) => (
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
Reference in New Issue
Block a user