XMarkdown和ThoughtChain搭配使用 #1680
Unanswered
momaekwudi
asked this question in
Q&A
Replies: 2 comments
-
|
XMarkdown 和 ThoughtChain 可以无缝结合实现流式输出和思维链展示。核心做法是:用自定义标签(如 关键要点:
ThoughtChain 的 items 是对象数组,支持 title、description、icon、extra、footer、content、status 等属性,content 可以是 React 组件或嵌套 ThoughtChain,支持高度自定义示例。 代码示例: import XMarkdown from '@ant-design/x-markdown';
import { ThoughtChain } from '@ant-design/x';
// 1. 先解码 HTML 实体
const srt = decodeHTMLEntities(`
<thought-chain>
<step data-title="分析问题" data-status="success">
<think>用户正在构建推理展示功能…</think>
</step>
<step data-title="最终结果" data-status="success">
代码块
\`\`\`js
console.log('Hello, ThoughtChain!');
\`\`\`
</step>
</thought-chain>
`);
// 2. 注册自定义组件
const Step = ({ children, domNode, streamStatus }) => (
<div className="step" data-status={domNode.attribs['data-status']}>
<XMarkdown content={children} />
{streamStatus === 'loading' && <div>Loading...</div>}
</div>
);
const CustomThoughtChain = ({ children }) => (
<ThoughtChain
items={
// 这里可以根据 domNode/children 解析出 items 结构
// 或直接渲染 children
[{ title: '自定义思维链', content: <XMarkdown content={children} /> }]
}
/>
);
<XMarkdown
content={srt}
streaming={{
hasNextChunk: true,
incompleteMarkdownComponentMap: { html: 'incomplete-xml' },
}}
components={{
step: Step,
'thought-chain': CustomThoughtChain,
'incomplete-xml': ({ domNode }) => <div>未闭合标签: {domNode?.data}</div>,
}}
/>常见坑点和最佳实践:详细说明和官方示例
更多流式动画、未闭合标签处理等进阶用法见 官方 streaming 文档。 To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
0 replies
-
我测试了下,好像没法实现流式渲染,在自定义标签输出完成之前,自定义组件的props的children总是空的,不知道是哪里有问题
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
流式输出中,使用XMarkdown的情况下,如何搭配ThoughtChain使用,并且构造出ThoughtChain所需的items,都需要构造什么样的自定义组件,有没有相关的示例指导下
Beta Was this translation helpful? Give feedback.
All reactions