rhua-chatgpt-web 1.0.93 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +223 -223
- package/dist/{api_chain-WFRw5ML6.js → api_chain-20qmBmlt.js} +2 -2
- package/dist/{api_chain-CIsWCKgO.cjs → api_chain-BZSxhO6w.cjs} +1 -1
- package/dist/{combine_docs_chain-DqweE4hu.js → combine_docs_chain-CDmPC9j3.js} +2 -2
- package/dist/{combine_docs_chain-CkTm-Y6L.cjs → combine_docs_chain-CbIBHz_O.cjs} +1 -1
- package/dist/{few_shot-CmdeM2Sr.cjs → few_shot-Cse9lSUl.cjs} +1 -1
- package/dist/{few_shot-kQ1bURcp.js → few_shot-DfBa9t3B.js} +1 -1
- package/dist/{index-CtmkEXCG.cjs → index-31BZbUUr.cjs} +1 -1
- package/dist/{index-Nt9bzxJ_.cjs → index-B41f3XKz.cjs} +1 -1
- package/dist/{index-D_TuMfnS.cjs → index-BM6gAiMn.cjs} +1 -1
- package/dist/{index-C8bFGXwg.js → index-Bpr1h_Sb.js} +154 -43
- package/dist/index-CEO5NUwI.js +4 -0
- package/dist/{index-BPX5EZOq.js → index-CMZ1iYNF.js} +1 -1
- package/dist/{index-bPzWh1YX.cjs → index-CadWq4hy.cjs} +1 -1
- package/dist/{index-BvWfN0UD.cjs → index-CpQhSxWi.cjs} +1 -1
- package/dist/{index-vxdzUOjI.cjs → index-D0xSgOzS.cjs} +1 -1
- package/dist/{index-wmWIMjxl.cjs → index-D7oNp3Pm.cjs} +3 -3
- package/dist/{index-DCl8PutS.cjs → index-DGmNs476.cjs} +1 -1
- package/dist/{index-D8eBKhCD.js → index-DKUZgpc6.js} +1 -1
- package/dist/{index-BwqspcrS.js → index-DLqxbJWX.js} +1 -1
- package/dist/index-DM1nrsZt.js +4 -0
- package/dist/{index-DGYrYxhA.cjs → index-DTEXidrg.cjs} +1 -1
- package/dist/{index-CESOAxk0.cjs → index-DVReuqWr.cjs} +1 -1
- package/dist/{index-Ibj7Di2W.js → index-Da-y319P.js} +2 -2
- package/dist/{index-CkLkNVjI.cjs → index-DvTAMnrH.cjs} +1 -1
- package/dist/index-DvzltS2g.js +4 -0
- package/dist/{index-Bx-JSxcE.cjs → index-EmBbPCdW.cjs} +1 -1
- package/dist/index-_1gNyqhr.js +4 -0
- package/dist/{index-RVAEf-1O.js → index-tBT9gQsn.js} +1 -1
- package/dist/{index-BQaCU-Zp.js → index-yZJRezRU.js} +1 -1
- package/dist/{index-DbigX4D6.js → index-zHbud3WS.js} +2 -2
- package/dist/index.cjs.js +1 -1
- package/dist/{index.es-C-eoW8oA.js → index.es-Blj5Atj5.js} +11 -11
- package/dist/{index.es-Cz-8rjns.cjs → index.es-CNLqGQVd.cjs} +2 -2
- package/dist/index.esm.js +1 -1
- package/dist/{llm_chain-BJGCHbKb.js → llm_chain-2sbPhu7X.js} +1 -1
- package/dist/{llm_chain-DNHnACm7.cjs → llm_chain-DmZ1DWv0.cjs} +1 -1
- package/dist/{sequential_chain-o9cEEPAB.cjs → sequential_chain-CdTyj5LA.cjs} +1 -1
- package/dist/{sequential_chain-DYCvZ3do.js → sequential_chain-MJvo-IhJ.js} +1 -1
- package/dist/tauri.svg +6 -6
- package/dist/{vector_db_qa-l1JxA-2O.js → vector_db_qa-C6Krwg5m.js} +3 -3
- package/dist/{vector_db_qa-B2bEMYL1.cjs → vector_db_qa-ayOVjhbO.cjs} +1 -1
- package/package.json +135 -135
- package/dist/index-7PhG3Bul.js +0 -4
- package/dist/index-BLKrtdG3.js +0 -4
- package/dist/index-BeyeAUBa.js +0 -4
- package/dist/index-DdHqkr9E.js +0 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Fei Tao
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Fei Tao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
# Rhua ChatGPT Web
|
|
2
|
-
|
|
3
|
-
一个基于 React 和 Semi Design 的 ChatGPT Web 界面组件库,提供完整的聊天界面、智能体管理、插件系统等功能。
|
|
4
|
-
|
|
5
|
-
## 特性
|
|
6
|
-
|
|
7
|
-
- 🎨 基于 Semi Design 的现代化 UI 设计
|
|
8
|
-
- 🤖 支持多种智能体和角色配置
|
|
9
|
-
- 🔌 可扩展的插件系统
|
|
10
|
-
- 📱 响应式设计,支持移动端
|
|
11
|
-
- 🗺️ 集成地图功能
|
|
12
|
-
- 📊 支持 Mermaid 图表渲染
|
|
13
|
-
- 🎯 完整的 TypeScript 支持
|
|
14
|
-
- 🌙 支持明暗主题切换
|
|
15
|
-
|
|
16
|
-
## 安装
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install rhua-chatgpt-web
|
|
20
|
-
# 或
|
|
21
|
-
yarn add rhua-chatgpt-web
|
|
22
|
-
# 或
|
|
23
|
-
pnpm add rhua-chatgpt-web
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## 依赖要求
|
|
27
|
-
|
|
28
|
-
确保你的项目中已安装以下 peer dependencies:
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm install react react-dom react-router-dom
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 快速开始
|
|
35
|
-
|
|
36
|
-
### 基础使用
|
|
37
|
-
|
|
38
|
-
```tsx
|
|
39
|
-
import React from "react";
|
|
40
|
-
import { XinXiaoYiChat } from "rhua-chatgpt-web";
|
|
41
|
-
import "rhua-chatgpt-web/styles";
|
|
42
|
-
|
|
43
|
-
function App() {
|
|
44
|
-
return (
|
|
45
|
-
<div className="App">
|
|
46
|
-
<XinXiaoYiChat />
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default App;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 使用单个组件
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
import React from "react";
|
|
58
|
-
import {
|
|
59
|
-
MessageBox,
|
|
60
|
-
BotMessageBox,
|
|
61
|
-
UserMessageBox,
|
|
62
|
-
SessionBox,
|
|
63
|
-
ChatHistory,
|
|
64
|
-
} from "rhua-chatgpt-web";
|
|
65
|
-
import "rhua-chatgpt-web/styles";
|
|
66
|
-
|
|
67
|
-
function MyChatApp() {
|
|
68
|
-
return (
|
|
69
|
-
<div>
|
|
70
|
-
<SessionBox />
|
|
71
|
-
<ChatHistory />
|
|
72
|
-
<BotMessageBox
|
|
73
|
-
message={{
|
|
74
|
-
id: "1",
|
|
75
|
-
type: "bot",
|
|
76
|
-
name: "Assistant",
|
|
77
|
-
content: "Hello! How can I help you?",
|
|
78
|
-
completed: true,
|
|
79
|
-
isMap: false,
|
|
80
|
-
}}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 使用设置页面
|
|
88
|
-
|
|
89
|
-
```tsx
|
|
90
|
-
import React from "react";
|
|
91
|
-
import {
|
|
92
|
-
SettingPage,
|
|
93
|
-
ModelIndex,
|
|
94
|
-
RoleIndex,
|
|
95
|
-
PluginIndex,
|
|
96
|
-
} from "rhua-chatgpt-web";
|
|
97
|
-
import "rhua-chatgpt-web/styles";
|
|
98
|
-
|
|
99
|
-
function SettingsApp() {
|
|
100
|
-
return (
|
|
101
|
-
<div>
|
|
102
|
-
<SettingPage />
|
|
103
|
-
{/* 或使用单独的子页面 */}
|
|
104
|
-
<ModelIndex />
|
|
105
|
-
<RoleIndex />
|
|
106
|
-
<PluginIndex />
|
|
107
|
-
</div>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## 主要组件
|
|
113
|
-
|
|
114
|
-
### 页面组件
|
|
115
|
-
|
|
116
|
-
- `XinXiaoYiChat` - 主要的聊天界面
|
|
117
|
-
- `CommentChat` - 评论式聊天界面
|
|
118
|
-
- `SettingPage` - 设置页面
|
|
119
|
-
- `LoginPage` - 登录页面
|
|
120
|
-
|
|
121
|
-
### 子组件
|
|
122
|
-
|
|
123
|
-
- `MessageBox` - 消息框组件
|
|
124
|
-
- `BotMessageBox` - 机器人消息框
|
|
125
|
-
- `UserMessageBox` - 用户消息框
|
|
126
|
-
- `UserMessageDocBox` - 用户文档消息框
|
|
127
|
-
- `SessionBox` - 会话管理组件
|
|
128
|
-
- `ChatHistory` - 聊天历史组件
|
|
129
|
-
- `AgentList` - 智能体列表组件
|
|
130
|
-
- `MapComponent` - 地图组件
|
|
131
|
-
- `MarkdownBox` - Markdown 渲染组件
|
|
132
|
-
- `MermaidBox` - Mermaid 图表组件
|
|
133
|
-
|
|
134
|
-
### 设置子页面
|
|
135
|
-
|
|
136
|
-
- `ModelIndex` - 模型设置
|
|
137
|
-
- `RoleIndex` - 角色设置
|
|
138
|
-
- `PluginIndex` - 插件设置
|
|
139
|
-
- `NormalIndex` - 常规设置
|
|
140
|
-
|
|
141
|
-
## 类型定义
|
|
142
|
-
|
|
143
|
-
```tsx
|
|
144
|
-
import type { ChatMessage, ChatSession, Agent, Role } from "rhua-chatgpt-web";
|
|
145
|
-
|
|
146
|
-
// 使用类型
|
|
147
|
-
const message: ChatMessage = {
|
|
148
|
-
id: "1",
|
|
149
|
-
type: "user",
|
|
150
|
-
name: "User",
|
|
151
|
-
content: "Hello!",
|
|
152
|
-
completed: true,
|
|
153
|
-
isMap: false,
|
|
154
|
-
};
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## 工具类
|
|
158
|
-
|
|
159
|
-
```tsx
|
|
160
|
-
import {
|
|
161
|
-
Storage,
|
|
162
|
-
MessageUtil,
|
|
163
|
-
PluginExecutor,
|
|
164
|
-
CommonUtil,
|
|
165
|
-
} from "rhua-chatgpt-web";
|
|
166
|
-
|
|
167
|
-
// 使用存储服务
|
|
168
|
-
const storage = new Storage();
|
|
169
|
-
await storage.setItem("key", "value");
|
|
170
|
-
|
|
171
|
-
// 使用消息工具
|
|
172
|
-
const messageUtil = new MessageUtil();
|
|
173
|
-
const processedMessage = messageUtil.processMessage(message);
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## 样式定制
|
|
177
|
-
|
|
178
|
-
组件库使用 Semi Design 主题系统,你可以通过 CSS 变量进行定制:
|
|
179
|
-
|
|
180
|
-
```css
|
|
181
|
-
:root {
|
|
182
|
-
--semi-color-primary: #1890ff;
|
|
183
|
-
--semi-color-success: #52c41a;
|
|
184
|
-
--semi-color-warning: #faad14;
|
|
185
|
-
--semi-color-danger: #f5222d;
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## 开发
|
|
190
|
-
|
|
191
|
-
```bash
|
|
192
|
-
# 克隆项目
|
|
193
|
-
git clone <repository-url>
|
|
194
|
-
|
|
195
|
-
# 安装依赖
|
|
196
|
-
pnpm install
|
|
197
|
-
|
|
198
|
-
# 开发模式
|
|
199
|
-
pnpm dev
|
|
200
|
-
|
|
201
|
-
# 构建库
|
|
202
|
-
pnpm build:lib
|
|
203
|
-
|
|
204
|
-
# 预览
|
|
205
|
-
pnpm preview
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## 许可证
|
|
209
|
-
|
|
210
|
-
MIT License
|
|
211
|
-
|
|
212
|
-
## 贡献
|
|
213
|
-
|
|
214
|
-
欢迎提交 Issue 和 Pull Request 来帮助改进这个项目。
|
|
215
|
-
|
|
216
|
-
## 更新日志
|
|
217
|
-
|
|
218
|
-
### 1.0.1
|
|
219
|
-
|
|
220
|
-
- 初始版本发布
|
|
221
|
-
- 支持基础聊天功能
|
|
222
|
-
- 支持智能体管理
|
|
223
|
-
- 支持插件系统
|
|
1
|
+
# Rhua ChatGPT Web
|
|
2
|
+
|
|
3
|
+
一个基于 React 和 Semi Design 的 ChatGPT Web 界面组件库,提供完整的聊天界面、智能体管理、插件系统等功能。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🎨 基于 Semi Design 的现代化 UI 设计
|
|
8
|
+
- 🤖 支持多种智能体和角色配置
|
|
9
|
+
- 🔌 可扩展的插件系统
|
|
10
|
+
- 📱 响应式设计,支持移动端
|
|
11
|
+
- 🗺️ 集成地图功能
|
|
12
|
+
- 📊 支持 Mermaid 图表渲染
|
|
13
|
+
- 🎯 完整的 TypeScript 支持
|
|
14
|
+
- 🌙 支持明暗主题切换
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install rhua-chatgpt-web
|
|
20
|
+
# 或
|
|
21
|
+
yarn add rhua-chatgpt-web
|
|
22
|
+
# 或
|
|
23
|
+
pnpm add rhua-chatgpt-web
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 依赖要求
|
|
27
|
+
|
|
28
|
+
确保你的项目中已安装以下 peer dependencies:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install react react-dom react-router-dom
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 快速开始
|
|
35
|
+
|
|
36
|
+
### 基础使用
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import React from "react";
|
|
40
|
+
import { XinXiaoYiChat } from "rhua-chatgpt-web";
|
|
41
|
+
import "rhua-chatgpt-web/styles";
|
|
42
|
+
|
|
43
|
+
function App() {
|
|
44
|
+
return (
|
|
45
|
+
<div className="App">
|
|
46
|
+
<XinXiaoYiChat />
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default App;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 使用单个组件
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import React from "react";
|
|
58
|
+
import {
|
|
59
|
+
MessageBox,
|
|
60
|
+
BotMessageBox,
|
|
61
|
+
UserMessageBox,
|
|
62
|
+
SessionBox,
|
|
63
|
+
ChatHistory,
|
|
64
|
+
} from "rhua-chatgpt-web";
|
|
65
|
+
import "rhua-chatgpt-web/styles";
|
|
66
|
+
|
|
67
|
+
function MyChatApp() {
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<SessionBox />
|
|
71
|
+
<ChatHistory />
|
|
72
|
+
<BotMessageBox
|
|
73
|
+
message={{
|
|
74
|
+
id: "1",
|
|
75
|
+
type: "bot",
|
|
76
|
+
name: "Assistant",
|
|
77
|
+
content: "Hello! How can I help you?",
|
|
78
|
+
completed: true,
|
|
79
|
+
isMap: false,
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 使用设置页面
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import React from "react";
|
|
91
|
+
import {
|
|
92
|
+
SettingPage,
|
|
93
|
+
ModelIndex,
|
|
94
|
+
RoleIndex,
|
|
95
|
+
PluginIndex,
|
|
96
|
+
} from "rhua-chatgpt-web";
|
|
97
|
+
import "rhua-chatgpt-web/styles";
|
|
98
|
+
|
|
99
|
+
function SettingsApp() {
|
|
100
|
+
return (
|
|
101
|
+
<div>
|
|
102
|
+
<SettingPage />
|
|
103
|
+
{/* 或使用单独的子页面 */}
|
|
104
|
+
<ModelIndex />
|
|
105
|
+
<RoleIndex />
|
|
106
|
+
<PluginIndex />
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 主要组件
|
|
113
|
+
|
|
114
|
+
### 页面组件
|
|
115
|
+
|
|
116
|
+
- `XinXiaoYiChat` - 主要的聊天界面
|
|
117
|
+
- `CommentChat` - 评论式聊天界面
|
|
118
|
+
- `SettingPage` - 设置页面
|
|
119
|
+
- `LoginPage` - 登录页面
|
|
120
|
+
|
|
121
|
+
### 子组件
|
|
122
|
+
|
|
123
|
+
- `MessageBox` - 消息框组件
|
|
124
|
+
- `BotMessageBox` - 机器人消息框
|
|
125
|
+
- `UserMessageBox` - 用户消息框
|
|
126
|
+
- `UserMessageDocBox` - 用户文档消息框
|
|
127
|
+
- `SessionBox` - 会话管理组件
|
|
128
|
+
- `ChatHistory` - 聊天历史组件
|
|
129
|
+
- `AgentList` - 智能体列表组件
|
|
130
|
+
- `MapComponent` - 地图组件
|
|
131
|
+
- `MarkdownBox` - Markdown 渲染组件
|
|
132
|
+
- `MermaidBox` - Mermaid 图表组件
|
|
133
|
+
|
|
134
|
+
### 设置子页面
|
|
135
|
+
|
|
136
|
+
- `ModelIndex` - 模型设置
|
|
137
|
+
- `RoleIndex` - 角色设置
|
|
138
|
+
- `PluginIndex` - 插件设置
|
|
139
|
+
- `NormalIndex` - 常规设置
|
|
140
|
+
|
|
141
|
+
## 类型定义
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import type { ChatMessage, ChatSession, Agent, Role } from "rhua-chatgpt-web";
|
|
145
|
+
|
|
146
|
+
// 使用类型
|
|
147
|
+
const message: ChatMessage = {
|
|
148
|
+
id: "1",
|
|
149
|
+
type: "user",
|
|
150
|
+
name: "User",
|
|
151
|
+
content: "Hello!",
|
|
152
|
+
completed: true,
|
|
153
|
+
isMap: false,
|
|
154
|
+
};
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 工具类
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import {
|
|
161
|
+
Storage,
|
|
162
|
+
MessageUtil,
|
|
163
|
+
PluginExecutor,
|
|
164
|
+
CommonUtil,
|
|
165
|
+
} from "rhua-chatgpt-web";
|
|
166
|
+
|
|
167
|
+
// 使用存储服务
|
|
168
|
+
const storage = new Storage();
|
|
169
|
+
await storage.setItem("key", "value");
|
|
170
|
+
|
|
171
|
+
// 使用消息工具
|
|
172
|
+
const messageUtil = new MessageUtil();
|
|
173
|
+
const processedMessage = messageUtil.processMessage(message);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 样式定制
|
|
177
|
+
|
|
178
|
+
组件库使用 Semi Design 主题系统,你可以通过 CSS 变量进行定制:
|
|
179
|
+
|
|
180
|
+
```css
|
|
181
|
+
:root {
|
|
182
|
+
--semi-color-primary: #1890ff;
|
|
183
|
+
--semi-color-success: #52c41a;
|
|
184
|
+
--semi-color-warning: #faad14;
|
|
185
|
+
--semi-color-danger: #f5222d;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## 开发
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# 克隆项目
|
|
193
|
+
git clone <repository-url>
|
|
194
|
+
|
|
195
|
+
# 安装依赖
|
|
196
|
+
pnpm install
|
|
197
|
+
|
|
198
|
+
# 开发模式
|
|
199
|
+
pnpm dev
|
|
200
|
+
|
|
201
|
+
# 构建库
|
|
202
|
+
pnpm build:lib
|
|
203
|
+
|
|
204
|
+
# 预览
|
|
205
|
+
pnpm preview
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 许可证
|
|
209
|
+
|
|
210
|
+
MIT License
|
|
211
|
+
|
|
212
|
+
## 贡献
|
|
213
|
+
|
|
214
|
+
欢迎提交 Issue 和 Pull Request 来帮助改进这个项目。
|
|
215
|
+
|
|
216
|
+
## 更新日志
|
|
217
|
+
|
|
218
|
+
### 1.0.1
|
|
219
|
+
|
|
220
|
+
- 初始版本发布
|
|
221
|
+
- 支持基础聊天功能
|
|
222
|
+
- 支持智能体管理
|
|
223
|
+
- 支持插件系统
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PromptTemplate, i as BaseChain } from "./index-
|
|
2
|
-
import { LLMChain } from "./llm_chain-
|
|
1
|
+
import { P as PromptTemplate, i as BaseChain } from "./index-Bpr1h_Sb.js";
|
|
2
|
+
import { LLMChain } from "./llm_chain-2sbPhu7X.js";
|
|
3
3
|
import "zod";
|
|
4
4
|
const API_URL_RAW_PROMPT_TEMPLATE = `You are given the below API Documentation:
|
|
5
5
|
{api_docs}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-D7oNp3Pm.cjs"),i=require("./llm_chain-DmZ1DWv0.cjs");require("zod");const t="You are given the below API Documentation:\n{api_docs}\nUsing this documentation, generate the full API url to call for answering the user question.\nYou should build the API url in order to get a response that is as short as possible, while still getting the necessary information to answer the question. Pay attention to deliberately exclude any unnecessary pieces of data in the API call.\n\nQuestion:{question}\nAPI url:",a=new e.PromptTemplate({inputVariables:["api_docs","question"],template:t}),n=`${t} {api_url}\n\nHere is the response from the API:\n\n{api_response}\n\nSummarize this response to answer the original question.\n\nSummary:`,s=new e.PromptTemplate({inputVariables:["api_docs","question","api_url","api_response"],template:n});class r extends e.BaseChain{get inputKeys(){return[this.inputKey]}get outputKeys(){return[this.outputKey]}constructor(e){super(e),Object.defineProperty(this,"apiAnswerChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiRequestChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiDocs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"headers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"question"}),Object.defineProperty(this,"outputKey",{enumerable:!0,configurable:!0,writable:!0,value:"output"}),this.apiRequestChain=e.apiRequestChain,this.apiAnswerChain=e.apiAnswerChain,this.apiDocs=e.apiDocs,this.inputKey=e.inputKey??this.inputKey,this.outputKey=e.outputKey??this.outputKey,this.headers=e.headers??this.headers}async _call(e,i){const t=e[this.inputKey],a=await this.apiRequestChain.predict({question:t,api_docs:this.apiDocs},null==i?void 0:i.getChild("request")),n=await fetch(a,{headers:this.headers}),s=await n.text(),r=await this.apiAnswerChain.predict({question:t,api_docs:this.apiDocs,api_url:a,api_response:s},null==i?void 0:i.getChild("response"));return{[this.outputKey]:r}}_chainType(){return"api_chain"}static async deserialize(e){const{api_request_chain:t,api_answer_chain:a,api_docs:n}=e;if(!t)throw new Error("LLMChain must have api_request_chain");if(!a)throw new Error("LLMChain must have api_answer_chain");if(!n)throw new Error("LLMChain must have api_docs");return new r({apiAnswerChain:await i.LLMChain.deserialize(a),apiRequestChain:await i.LLMChain.deserialize(t),apiDocs:n})}serialize(){return{_type:this._chainType(),api_answer_chain:this.apiAnswerChain.serialize(),api_request_chain:this.apiRequestChain.serialize(),api_docs:this.apiDocs}}static fromLLMAndAPIDocs(e,t,n={}){const{apiUrlPrompt:r=a,apiResponsePrompt:o=s}=n,u=new i.LLMChain({prompt:r,llm:e});return new this({apiAnswerChain:new i.LLMChain({prompt:o,llm:e}),apiRequestChain:u,apiDocs:t,...n})}}exports.APIChain=r;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "zod";
|
|
2
|
-
import { i as BaseChain, P as PromptTemplate } from "./index-
|
|
3
|
-
import { LLMChain } from "./llm_chain-
|
|
2
|
+
import { i as BaseChain, P as PromptTemplate } from "./index-Bpr1h_Sb.js";
|
|
3
|
+
import { LLMChain } from "./llm_chain-2sbPhu7X.js";
|
|
4
4
|
class StuffDocumentsChain extends BaseChain {
|
|
5
5
|
static lc_name() {
|
|
6
6
|
return "StuffDocumentsChain";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),require("zod");const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),require("zod");const e=require("./index-D7oNp3Pm.cjs"),t=require("./llm_chain-DmZ1DWv0.cjs");class i extends e.BaseChain{static lc_name(){return"StuffDocumentsChain"}get inputKeys(){return[this.inputKey,...this.llmChain.inputKeys].filter(e=>e!==this.documentVariableName)}get outputKeys(){return this.llmChain.outputKeys}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),this.llmChain=e.llmChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.inputKey=e.inputKey??this.inputKey}_prepInputs(e){if(!(this.inputKey in e))throw new Error(`Document key ${this.inputKey} not found.`);const{[this.inputKey]:t,...i}=e,n=t.map(({pageContent:e})=>e).join("\n\n");return{...i,[this.documentVariableName]:n}}async _call(e,t){return await this.llmChain.call(this._prepInputs(e),null==t?void 0:t.getChild("combine_documents"))}_chainType(){return"stuff_documents_chain"}static async deserialize(e){if(!e.llm_chain)throw new Error("Missing llm_chain");return new i({llmChain:await t.LLMChain.deserialize(e.llm_chain)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize()}}}class n extends e.BaseChain{static lc_name(){return"MapReduceDocumentsChain"}get inputKeys(){return[this.inputKey,...this.combineDocumentChain.inputKeys]}get outputKeys(){return this.combineDocumentChain.outputKeys}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),Object.defineProperty(this,"returnIntermediateSteps",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:3e3}),Object.defineProperty(this,"maxIterations",{enumerable:!0,configurable:!0,writable:!0,value:10}),Object.defineProperty(this,"ensureMapStep",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"combineDocumentChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.llmChain=e.llmChain,this.combineDocumentChain=e.combineDocumentChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.ensureMapStep=e.ensureMapStep??this.ensureMapStep,this.inputKey=e.inputKey??this.inputKey,this.maxTokens=e.maxTokens??this.maxTokens,this.maxIterations=e.maxIterations??this.maxIterations,this.returnIntermediateSteps=e.returnIntermediateSteps??!1}async _call(e,t){if(!(this.inputKey in e))throw new Error(`Document key ${this.inputKey} not found.`);const{[this.inputKey]:i,...n}=e;let a=i,r=[];for(let o=0;o<this.maxIterations;o+=1){const e=a.map(e=>({[this.documentVariableName]:e.pageContent,...n}));if(0!==o||!this.ensureMapStep){const e=await this.combineDocumentChain.llmChain.prompt.format(this.combineDocumentChain._prepInputs({[this.combineDocumentChain.inputKey]:a,...n}));if(await this.combineDocumentChain.llmChain._getNumTokens(e)<this.maxTokens)break}const i=await this.llmChain.apply(e,t?Array.from({length:e.length},(e,i)=>t.getChild(`map_${i+1}`)):void 0),{outputKey:s}=this.llmChain;this.returnIntermediateSteps&&(r=r.concat(i.map(e=>e[s]))),a=i.map(e=>({pageContent:e[s],metadata:{}}))}const s={[this.combineDocumentChain.inputKey]:a,...n},u=await this.combineDocumentChain.call(s,null==t?void 0:t.getChild("combine_documents"));return this.returnIntermediateSteps?{...u,intermediateSteps:r}:u}_chainType(){return"map_reduce_documents_chain"}static async deserialize(e){if(!e.llm_chain)throw new Error("Missing llm_chain");if(!e.combine_document_chain)throw new Error("Missing combine_document_chain");return new n({llmChain:await t.LLMChain.deserialize(e.llm_chain),combineDocumentChain:await i.deserialize(e.combine_document_chain)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize(),combine_document_chain:this.combineDocumentChain.serialize()}}}class a extends e.BaseChain{static lc_name(){return"RefineDocumentsChain"}get defaultDocumentPrompt(){return new e.PromptTemplate({inputVariables:["page_content"],template:"{page_content}"})}get inputKeys(){return[...new Set([this.inputKey,...this.llmChain.inputKeys,...this.refineLLMChain.inputKeys])].filter(e=>e!==this.documentVariableName&&e!==this.initialResponseName)}get outputKeys(){return[this.outputKey]}constructor(e){super(e),Object.defineProperty(this,"llmChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"inputKey",{enumerable:!0,configurable:!0,writable:!0,value:"input_documents"}),Object.defineProperty(this,"outputKey",{enumerable:!0,configurable:!0,writable:!0,value:"output_text"}),Object.defineProperty(this,"documentVariableName",{enumerable:!0,configurable:!0,writable:!0,value:"context"}),Object.defineProperty(this,"initialResponseName",{enumerable:!0,configurable:!0,writable:!0,value:"existing_answer"}),Object.defineProperty(this,"refineLLMChain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"documentPrompt",{enumerable:!0,configurable:!0,writable:!0,value:this.defaultDocumentPrompt}),this.llmChain=e.llmChain,this.refineLLMChain=e.refineLLMChain,this.documentVariableName=e.documentVariableName??this.documentVariableName,this.inputKey=e.inputKey??this.inputKey,this.outputKey=e.outputKey??this.outputKey,this.documentPrompt=e.documentPrompt??this.documentPrompt,this.initialResponseName=e.initialResponseName??this.initialResponseName}async _constructInitialInputs(e,t){const i={page_content:e.pageContent,...e.metadata},n={};this.documentPrompt.inputVariables.forEach(e=>{n[e]=i[e]});return{...{[this.documentVariableName]:await this.documentPrompt.format({...n})},...t}}async _constructRefineInputs(e,t){const i={page_content:e.pageContent,...e.metadata},n={};this.documentPrompt.inputVariables.forEach(e=>{n[e]=i[e]});const a={[this.documentVariableName]:await this.documentPrompt.format({...n})};return{[this.initialResponseName]:t,...a}}async _call(e,t){if(!(this.inputKey in e))throw new Error(`Document key ${this.inputKey} not found.`);const{[this.inputKey]:i,...n}=e,a=i,r=await this._constructInitialInputs(a[0],n);let s=await this.llmChain.predict({...r},null==t?void 0:t.getChild("answer"));for(let u=1;u<a.length;u+=1){const e={...await this._constructRefineInputs(a[u],s),...n};s=await this.refineLLMChain.predict({...e},null==t?void 0:t.getChild("refine"))}return{[this.outputKey]:s}}_chainType(){return"refine_documents_chain"}static async deserialize(e){const i=e.llm_chain;if(!i)throw new Error("Missing llm_chain");const n=e.refine_llm_chain;if(!n)throw new Error("Missing refine_llm_chain");return new a({llmChain:await t.LLMChain.deserialize(i),refineLLMChain:await t.LLMChain.deserialize(n)})}serialize(){return{_type:this._chainType(),llm_chain:this.llmChain.serialize(),refine_llm_chain:this.refineLLMChain.serialize()}}}exports.MapReduceDocumentsChain=n,exports.RefineDocumentsChain=a,exports.StuffDocumentsChain=i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-D7oNp3Pm.cjs");require("zod");class t extends e.BaseStringPromptTemplate{constructor(t){if(super(t),Object.defineProperty(this,"lc_serializable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"examples",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"exampleSelector",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"examplePrompt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"suffix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"exampleSeparator",{enumerable:!0,configurable:!0,writable:!0,value:"\n\n"}),Object.defineProperty(this,"prefix",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"templateFormat",{enumerable:!0,configurable:!0,writable:!0,value:"f-string"}),Object.defineProperty(this,"validateTemplate",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.assign(this,t),void 0!==this.examples&&void 0!==this.exampleSelector)throw new Error("Only one of 'examples' and 'example_selector' should be provided");if(void 0===this.examples&&void 0===this.exampleSelector)throw new Error("One of 'examples' and 'example_selector' should be provided");if(this.validateTemplate){let t=this.inputVariables;this.partialVariables&&(t=t.concat(Object.keys(this.partialVariables))),e.checkValidTemplate(this.prefix+this.suffix,this.templateFormat,t)}}_getPromptType(){return"few_shot"}static lc_name(){return"FewShotPromptTemplate"}async getExamples(e){if(void 0!==this.examples)return this.examples;if(void 0!==this.exampleSelector)return this.exampleSelector.selectExamples(e);throw new Error("One of 'examples' and 'example_selector' should be provided")}async partial(e){const r=this.inputVariables.filter(t=>!(t in e)),a={...this.partialVariables??{},...e},i={...this,inputVariables:r,partialVariables:a};return new t(i)}async format(t){const r=await this.mergePartialAndUserVariables(t),a=await this.getExamples(r),i=await Promise.all(a.map(e=>this.examplePrompt.format(e))),l=[this.prefix,...i,this.suffix].join(this.exampleSeparator);return e.renderTemplate(l,this.templateFormat,r)}serialize(){if(this.exampleSelector||!this.examples)throw new Error("Serializing an example selector is not currently supported");if(void 0!==this.outputParser)throw new Error("Serializing an output parser is not currently supported");return{_type:this._getPromptType(),input_variables:this.inputVariables,example_prompt:this.examplePrompt.serialize(),example_separator:this.exampleSeparator,suffix:this.suffix,prefix:this.prefix,template_format:this.templateFormat,examples:this.examples}}static async deserialize(r){const{example_prompt:a}=r;if(!a)throw new Error("Missing example prompt");const i=await e.PromptTemplate.deserialize(a);let l;if(!Array.isArray(r.examples))throw new Error("Invalid examples format. Only list or string are supported.");return l=r.examples,new t({inputVariables:r.input_variables,examplePrompt:i,examples:l,exampleSeparator:r.example_separator,prefix:r.prefix,suffix:r.suffix,templateFormat:r.template_format})}}exports.FewShotPromptTemplate=t;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BaseStringPromptTemplate, e as checkValidTemplate, g as renderTemplate, P as PromptTemplate } from "./index-
|
|
1
|
+
import { B as BaseStringPromptTemplate, e as checkValidTemplate, g as renderTemplate, P as PromptTemplate } from "./index-Bpr1h_Sb.js";
|
|
2
2
|
import "zod";
|
|
3
3
|
class FewShotPromptTemplate extends BaseStringPromptTemplate {
|
|
4
4
|
constructor(input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-D7oNp3Pm.cjs");exports.default=e.remarkGfm;
|