mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 23:46:50 +00:00
fix(reasoning): prevent LLM-hallucinated HTML tags from rendering as DOM elements (#2321)
* fix * add test * fix
This commit is contained in:
@@ -11,6 +11,7 @@ import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
|||||||
import type { ComponentProps, ReactNode } from "react";
|
import type { ComponentProps, ReactNode } from "react";
|
||||||
import { createContext, memo, useContext, useEffect, useState } from "react";
|
import { createContext, memo, useContext, useEffect, useState } from "react";
|
||||||
import { Streamdown } from "streamdown";
|
import { Streamdown } from "streamdown";
|
||||||
|
import { reasoningPlugins } from "@/core/streamdown/plugins";
|
||||||
import { Shimmer } from "./shimmer";
|
import { Shimmer } from "./shimmer";
|
||||||
|
|
||||||
type ReasoningContextValue = {
|
type ReasoningContextValue = {
|
||||||
@@ -177,7 +178,7 @@ export const ReasoningContent = memo(
|
|||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Streamdown {...props}>{children}</Streamdown>
|
<Streamdown {...reasoningPlugins}>{children}</Streamdown>
|
||||||
</CollapsibleContent>
|
</CollapsibleContent>
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,6 +28,15 @@ export const streamdownPluginsWithWordAnimation = {
|
|||||||
] as StreamdownProps["rehypePlugins"],
|
] as StreamdownProps["rehypePlugins"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Plugins for reasoning/thinking content — derived from streamdownPlugins but without rehypeRaw,
|
||||||
|
// to prevent LLM-hallucinated HTML tags (e.g. <simd>) from being rendered as DOM elements.
|
||||||
|
export const reasoningPlugins = {
|
||||||
|
remarkPlugins: streamdownPlugins.remarkPlugins,
|
||||||
|
rehypePlugins: streamdownPlugins.rehypePlugins?.filter(
|
||||||
|
(p) => p !== rehypeRaw,
|
||||||
|
) as StreamdownProps["rehypePlugins"],
|
||||||
|
};
|
||||||
|
|
||||||
// Plugins for human messages - no autolink to prevent URL bleeding into adjacent text
|
// Plugins for human messages - no autolink to prevent URL bleeding into adjacent text
|
||||||
export const humanMessagePlugins = {
|
export const humanMessagePlugins = {
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import rehypeRaw from "rehype-raw";
|
||||||
|
import { expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { reasoningPlugins, streamdownPlugins } from "@/core/streamdown/plugins";
|
||||||
|
|
||||||
|
test("streamdownPlugins includes rehypeRaw", () => {
|
||||||
|
expect(streamdownPlugins.rehypePlugins).toContain(rehypeRaw);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("reasoningPlugins does not include rehypeRaw", () => {
|
||||||
|
const flat = reasoningPlugins.rehypePlugins?.flat();
|
||||||
|
expect(flat).not.toContain(rehypeRaw);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user