validate messages (#2139)

This commit is contained in:
pablodanswer
2024-08-14 15:06:48 -07:00
committed by GitHub
parent 2ab192933b
commit d9bcacfae7

View File

@@ -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"