36 |
37 | 在上述代码中,我们通过设置 `render` 函数来自定义通知类消息的展示方式。当检测到消息来源角色为 `notification`时,将默认展示替换成带有警告图标和信息提示的 `Alert` 组件。
38 |
39 | ### 表单提交
40 |
41 |
42 |
43 | 在上述代码中,我们通过设置 `contentRender` 函数配合特殊的元数据,做到了代入参数让 AI 执行填写表单的逻辑。
44 |
45 | ### 深度交互逻辑
46 |
47 |
48 |
49 | 这个代码展示了一个非常特殊的交互场景,你可以依靠上下文非常动态的调整你需要的渲染内容。
50 |
51 | ## 源码中影响范围
52 |
53 | 源码里面关于如何根据配置对象 `chatItemRenderConfig` 中提供的相关渲染方法来构建每个聊天项(即每条消息)。以下是关键点解释:
54 |
55 | 1. 对于头像 (`avatar`)、标题 (`title`)、内容 (`content`) 和操作按钮 (`actions`) 等部分均有独立的 useMemo 钩子进行处理,并且可通过相应参数进行自定义。
56 | 2. 如果提供了总体自定义渲染方法 (`render`) 并且返回非空结果,则会优先使用该方法直接返回最终 DOM 结构。
57 | 3. 所有 useMemo 钩子和最后返回结构都依赖于外部传入的 `chatItemRenderConfig` 参数。
58 |
59 | 注意:若要正确地使用此API,请确保你对React以及Ant Design库有一定程度上的理解,并且能够编写相应类型符合预期要求与逻辑业务场景匹配的自定义函数。
60 |
--------------------------------------------------------------------------------
/docs/guide/chatRef.en-US.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: chatRef
3 | group:
4 | title: Hooks
5 | order: 100
6 | nav:
7 | title: Documents
8 | order: 0
9 | ---
10 |
--------------------------------------------------------------------------------
/docs/guide/chatRef.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: chatRef
3 | group:
4 | title: Hooks
5 | order: 100
6 | nav:
7 | title: 文档
8 | order: 0
9 | ---
10 |
--------------------------------------------------------------------------------
/docs/guide/demos/base.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * compact: true
3 | */
4 | import { ProChat } from '@ant-design/pro-chat';
5 |
6 | import { useTheme } from 'antd-style';
7 |
8 | export default () => {
9 | const theme = useTheme();
10 | return (
11 |
38 |
39 | ### 🚧 Using atomization ability
40 |
41 | > Working in Progress At present, this part of the capability is still under high-speed development, please stay tuned。
42 |
43 | ProChat will provide a series of atomized components in the future. In special cases, you may want to use some independent components in ProChat. We will also provide similar components to help you better build applications.
44 |
45 | If you have more ideas and needs,Welcome to [Issue](https://github.com/ant-design/pro-chat/issues) and contact us on [Discussions](https://github.com/ant-design/pro-chat/discussions)
46 |
47 | > Our next plan is to provide a complex model parameter panel: Welcome to watch [「RFC」New Component:ModalConfig Model Parameters Panel](https://github.com/ant-design/pro-chat/discussions/58)
48 |
49 | Some of the underlying components, such as Markdown, Highlight, etc., we rely on the [ProEditor UI Component Library](https://github.com/ant-design/pro-editor)So if you also have a scenario of building an editor, you can come here to take a look.
50 |
51 | ## Engineering capability
52 |
53 | ### On demand loading
54 |
55 | ProChat supports tree Shaking based on ES modules by default, directly introducing `import {ProChat} from' @ ant design/pro chat` ; There will be an on-demand loading effect.
56 |
57 | ### TypeScript
58 |
59 | ProChat is developed using TypeScript, thus providing a complete type definition.
60 |
--------------------------------------------------------------------------------
/docs/guide/intro-start.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 快速开始
3 | group:
4 | title: 快速上手
5 | order: 0
6 | nav:
7 | title: 文档
8 | order: 0
9 | ---
10 |
11 | # 快速开始
12 |
13 | ProEditor 定位为 Chat 对话模式下,给前端提供快速搭建对话内容的组件库
14 |
15 | ## 安装
16 |
17 | ```bash
18 | # @ant-design/pro-editor 基于 antd 和 antd-style,需要在项目中安装
19 | $ npm install antd antd-style -S
20 | $ npm install @ant-design/pro-chat -S
21 | ```
22 |
23 | 因为底层依赖于 antd ,因此对版本有所要求
24 |
25 | ```json
26 | "peerDependencies": {
27 | "antd": "^5",
28 | "antd-style": "^3",
29 | "react": "^18"
30 | },
31 | ```
32 |
33 | ### 使用 ProChat 组件
34 |
35 | ProChat 提供的最关键的组件就是 ProChat 组件,你可以你可以非常简单的使用它。
36 |
37 |
38 |
39 | ### 🚧 使用原子化能力
40 |
41 | > Working in Progress 当前该部分能力仍处于高速开发中,敬请期待。
42 |
43 | ProChat 后续会提供一系列原子化的组件,在特殊情况下你可能会想要使用某些 ProChat 中的独立组件,这些需求我们也会提供类似的组件来帮助大家更好的搭建应用。
44 |
45 | 如果你有更多想法和需求,欢迎来 [Issue](https://github.com/ant-design/pro-chat/issues) 和 [讨论区](https://github.com/ant-design/pro-chat/discussions) 和我们沟通!
46 |
47 | > 我们下一个计划是提供一个复杂的模型参数面板:欢迎围观 [「RFC」New Component:ModalConfig 模型参数面板](https://github.com/ant-design/pro-chat/discussions/58)
48 |
49 | 有部分的底层组件,例如 Markdown、Highlight 之类的,我们会依赖于 [ProEditor - 编辑器 UI 组件库](https://github.com/ant-design/pro-editor),因此如果你也有搭建编辑器的场景,可以来这里看看。
50 |
51 | ## 工程化能力
52 |
53 | ### 按需加载
54 |
55 | ProChat 默认支持基于 ES modules 的 tree shaking,直接引入 `import { ProChat } from '@ant-design/pro-chat`; 就会有按需加载的效果。
56 |
57 | ### TypeScript
58 |
59 | ProChat 使用 TypeScript 进行开发,因此提供了完整的类型定义。
60 |
--------------------------------------------------------------------------------
/docs/guide/multimodal.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 多模态怎么接入
3 | order: 19
4 | group:
5 | title: 使用案例
6 | nav:
7 | title: 文档
8 | order: 0
9 | ---
10 |
11 | # 多模态怎么接入
12 |
13 | 一开始我们打算直接让 InputArea(即下方的输入框)支持上传各种各样的文件
14 |
15 | 但是一旦这么设计,就会导致更多的问题
16 |
17 | - 图片我们是直接转 Base64 还是 Cdn?如果是 Cdn 是不是还需要提供一个 Cdn 的 api 给开发者?
18 | - 图片还好说,但是除开图片之外的其他文件呢?各种文件是否需要预览?
19 | - 这些文件到底以怎么样的形式拼接到 Prompt 中去呢?怎么定义这个 Prompt 的位置?
20 |
21 | 等等这些设计细节数不甚数,而且对于一些模型来说,并不一定支持多模态,默认提供分析下来并不是一个好的设计。
22 |
23 | ## 自定义输入部分
24 |
25 | 我们提供了一个 inputAreaRender 的 api,来帮助你对多模态的情况下进行支持,以及和 ProChat 的数据流进行接入和交互
26 |
27 | ```ts
28 | inputAreaRender?: (
29 | defaultDom: ReactNode,
30 | onMessageSend: (message: string) => void | Promise
46 |
47 | 我们来详细拆解下这个案例
48 |
49 | ### 默认使用Base64
50 |
51 | 案例中使用了 antd 的 Upload 组件,我们可以轻易拿到当前内容的 Base64,然后在 onMessageSend 将其进行组合
52 |
53 | 如果你想用 CDN 代替 Base64,你需要做的事情就是在数据流上做处理。
54 |
55 | > 下面这个改动是建立在,Upload 组件配置的 actions 接口如果有 response 返回,里面有一个 cdnUrl 返回告诉当前文件上传完毕后的 Cdn 链接在哪里
56 |
57 | ```js
58 | onFinish={async (value) => {
59 | const { question, files } = value;
60 | const FilesCdnList = files?.fileList.map(
61 | (file: any) => ``,
62 | );
63 | const Prompt = `${question} ${FilesCdnList?.join('\n')}`;
64 | await onMessageSend(Prompt);
65 | }}
66 | ```
67 |
68 | ### 非图片的内容支持
69 |
70 | 可以看到,本质上预览是依赖于 Markdown 的预览能力进行支持的,如果遇到了内容的文件,我们建议采用 `` 来进行渲染,然后使用 messageItemExtraRender 在下方进行额外文件的预览渲染
71 |
72 | > 其实 Markdown 是支持 Html 渲染的,但是我们默认并没有开启这个能力,考虑各方面我们并不打算默认打开这个,我们建议你采用 messageItemExtraRender
73 |
74 | ```ts
75 | messageItemExtraRender: (message: ChatMessage, type: 'assistant' | 'user') => React.ReactNode;
76 | ```
77 |
78 | messageItemExtraRender 可以拿到当前的 message,可以做很多自定义渲染的工作。
79 |
--------------------------------------------------------------------------------
/docs/guide/servers-push.en-US.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: The method of server push
3 | order: 20
4 | group:
5 | title: Use Cases
6 | nav:
7 | title: Documents
8 | order: 0
9 | ---
10 |
11 | ## The method of server push
12 |
13 | Many times, we need scenarios for server-side push, such as:
14 |
15 | -The token limit has been reached, and users need to be prompted to recharge -Some of the calls behind FunctionCall will be executed for a long time, and a message will be pushed after the execution
16 |
17 | In this case, it is somewhat different from a regular Request or SSE, and even the triggering time may not necessarily be related to the conversation request
18 |
19 | This problem can be simplified as:
20 |
21 | -How to send/receive a piece of content (timing uncertain)
22 |
23 | ProChat is very flexible in this situation, and we offer several methods to help you
24 |
25 | ### Controlled mode
26 |
27 | In this case, we waited for 3 seconds before actively pushing a notification, and then controlled it through chats and placed it in the last piece of content
28 |
29 | > In this case, we also used the render in chatitemRenderConfig to customize a special format of information. For more information about this API, please refer to [Deep Customization Conversation Content](./chatItemRenderConfig.md)
30 |
31 |
32 |
33 | ### Hooks sendMessage
34 |
35 | > Working on Progress
36 |
--------------------------------------------------------------------------------
/docs/guide/servers-push.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 服务端推送的方式
3 | order: 20
4 | group:
5 | title: 使用案例
6 | nav:
7 | title: 文档
8 | order: 0
9 | ---
10 |
11 | ## 服务端推送的方式
12 |
13 | 很多时候,我们会需要一些服务端推送的场景,例如:
14 |
15 | - 使用 Token 上限了,需要提示用户去充值
16 | - 有一些背后调用了 FunctionCall 会执行很久,执行结束后 Push 一条内容
17 |
18 | 这种情况下和普通的 Request 或 SSE 有些不一样,甚至触发时机都不一定和对话请求有关
19 |
20 | 这个问题可以简化为:
21 |
22 | - 如何 发送/接收 一条内容(时机不确定)
23 |
24 | ProChat 在这种情况下很灵活,我们提供几种方法来帮助你
25 |
26 | ### 受控模式
27 |
28 | 在这个案例里面,我们等待 3s 后主动推送了一条通知,然后通过 chats 进行受控放到了最后一条内容中
29 |
30 | > 这个案例里面我们还使用了 chatItemRenderConfig 里面的 render 自定义了一条特殊格式的信息,关于这个 api 的更多信息可见[深度自定义对话内容](./chatItemRenderConfig.md)
31 |
32 |
33 |
34 | ### Hooks sendMessage
35 |
36 | > working on Progress
37 |
--------------------------------------------------------------------------------
/docs/guide/styles.en-US.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Custom Style
3 | order: 20
4 | group:
5 | title: Use Cases
6 | nav:
7 | title: Documents
8 | order: 0
9 | ---
10 |
11 | ## Custom Style
12 |
13 | Overall, for ProChat, due to the use of AntDesign components and design, the style remains consistent
14 |
15 | At the same time, we also support different degrees of custom styles
16 |
17 | ### Input box area style
18 |
19 | InputAreaProps allows you to pass Props (i.e. Props supported by antd Input. Area) through the input box, where ClassName or Style can be inserted to modify the style.
20 |
21 | Below, I have changed the border color and font color of the input box
22 |
23 |
24 |
25 | ### Conversation Record Style
26 |
27 | We have a chatitemRenderConfiguration method that allows you to customize all the content of a conversation. This API is very powerful, and rendering of conversation content will come to this point. Avatar, content area, and operation area can all be modified by magic
28 |
29 | I have individually wrapped a blue border for the content area below
30 |
31 |
32 |
33 | ### Overwrite with ClassName style
34 |
35 | This is the simplest and most convenient style overlay method. We have added ClassNames to many places, and you only need to open devtools to see some names
36 |
37 | > Note: If you find that this ClassName does not look like a normal class name, it indicates that this class is using Hash's ClassName, which will dynamically change. Please do not overwrite this class name
38 |
39 | In the following case, I used ant styles (an ant css in js enterprise solution) to style overlay the background of the content area
40 |
41 |
42 |
43 | ### Theme customization
44 |
45 | If you want global style customization, such as leveraging antd's custom themes and algorithmic capabilities, we provide a set of code below in conjunction with antd styles. For more details, please refer to [antd styles](https://ant-design.github.io/antd-style/zh-CN/guide)
46 |
47 |
48 |
--------------------------------------------------------------------------------
/docs/guide/styles.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 自定义样式
3 | order: 20
4 | group:
5 | title: 使用案例
6 | nav:
7 | title: 文档
8 | order: 0
9 | ---
10 |
11 | ## 自定义样式
12 |
13 | 整体对于 ProChat 来说,因为使用了 AntDesign 组件和设计,风格上是保持统一的
14 |
15 | 同时我们也支持不同程度的自定义样式
16 |
17 | ### 输入框区域样式
18 |
19 | inputAreaProps 允许你给输入框透传 Props(即 antd Input.Area 支持的 Props),里面可以穿入 ClassName 或 Style 来修改样式。
20 |
21 | 下面我改动了输入框的边框颜色和字体颜色
22 |
23 |
24 |
25 | ### 对话记录样式
26 |
27 | 我们有一个 chatItemRenderConfig 方法,可以让你自定义对话的所有内容,这个 api 很强大,涉及到对话内容的渲染都会走到这里,头像、内容区域、操作区域都可以进行魔改
28 |
29 | 下面我单独给内容区包裹了一个蓝色边框 border
30 |
31 |
32 |
33 | ### 使用 ClassName 样式覆盖
34 |
35 | 这个是最简单最方便的样式覆盖方法,我们给很多地方添加了 ClassName,你只需要打开 devtools 就可以看到一些名称
36 |
37 | > 注意:如果你发现这个 ClassName 看上去不像是一个正常的类名,说明这类用的是 Hash 的 ClassName,会动态变化,请不要覆盖这一类类名
38 |
39 | 下面的这个案例中我使用 antd-styles(一个 antd 的 css-in-js 企业级解决方案)来对内容区域的背景做了样式覆盖
40 |
41 |
42 |
43 | ### 主题定制
44 |
45 | 如果你想要全局的样式定制,例如想要利用到 antd 的自定义主题、算法能力,我们结合 antd-styles 在下面提供这样一套代码,详情的使用可见 [antd-styles](https://ant-design.github.io/antd-style/zh-CN/guide)
46 |
47 |
48 |
--------------------------------------------------------------------------------
/docs/guide/umi.en-US.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Umi
3 | group:
4 | title: Frontend framework
5 | order: 51
6 | nav:
7 | title: Documents
8 | order: 0
9 | ---
10 |
11 | ## Integrate with umi
12 |
13 | In the R&D scenario of the backend, [umi](https://umijs.org/)It is a very good choice. The integration of ProChat and umi is very easy. After installation, it can be used directly.
14 |
15 | ```bash
16 | npx create-umi@latest
17 | or
18 | yarn create umi
19 | pnpm dlx create-umi@latest
20 | ```
21 |
22 | ### Installation dependencies
23 |
24 | After creation
25 |
26 | ```bash
27 | npm install @ant-design/pro-chat --save
28 | or
29 | pnpm install @ant-design/pro-chat
30 | ```
31 |
32 | ### Usage
33 |
34 | ```js
35 | import { useState, useEffect } from 'react';
36 | import { ProChat } from '@ant-design/pro-chat';
37 | export default () => (
38 |
75 |
76 | 而针对多行代码块,我们则强化了代码块组件的交互能力,使之具有折叠展开、更换高亮语言等进阶功能,进而帮助你在日常使用 AI 大模型中更好地查看AI生成的代码。
77 |
78 | {item}
13 | ))} 14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
12 |
13 | ## Alert
14 |
15 |
16 |
17 | ## APIs
18 |
19 |
12 |
13 | ## Alert
14 |
15 |
16 |
17 | ## APIs
18 |
19 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
11 |
12 | ## APIs
13 |
14 |
14 |
15 | ## APIs
16 |
17 |
14 |
15 | ## APIs
16 |
17 |