@infinilabs/ai-chat 0.0.0

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/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @infinilabs/ai-chat
2
+
3
+ 这是一个 AI Chat 组件库,用于在 React 应用中集成 AI 聊天功能。
4
+
5
+ ## 项目简介
6
+
7
+ 1. 项目是 pnpm 项目,执行命令需要用 pnpm
8
+ 2. 项目是 AI Chat 组件库,最后是需要 pnpm build 之后部署发布 npm 库的
9
+
10
+ ## 对外的参数
11
+
12
+ 1. 需要获取历史数据的方法,支持组件内部调用获取数据
13
+ ```ts
14
+ const [_error, res] = await Get(`/chat/_history`, {
15
+ from: 0,
16
+ size: 100,
17
+ });
18
+ ```
19
+ 2. 需要删除历史记录的方法,支持组件内部调用操作数据
20
+ 3. 需要获取小助手列表数据的方法,支持组件内部调用获取数据
21
+ 4. 需要创建新的会话的方法,支持组件内部调用获取第一次聊天的数据
22
+ ```ts
23
+ await streamPost({
24
+ url: "/chat/_create",
25
+ body: { message },
26
+ queryParams,
27
+ onMessage: (line) => {
28
+ // console.log("⏳", line);
29
+ handleChatCreateStreamMessage(line);
30
+ // append to chat box
31
+ },
32
+ });
33
+ ```
34
+ 5. 需要继续聊天的方法,支持组件内部调用获取继续聊天的数据
35
+ ```ts
36
+ await streamPost({
37
+ url: `/chat/${newChat?._id}/_chat`,
38
+ body: { message },
39
+ queryParams,
40
+ onMessage: (line) => {
41
+ // console.log("line", line);
42
+ handleChatCreateStreamMessage(line);
43
+ // append to chat box
44
+ },
45
+ });
46
+ ```
47
+ 6. 需要取消聊天的方法,支持组件内部调用取消聊天
48
+ ```ts
49
+ const [_error, res] = await Post(
50
+ `/chat/${activeChat?._id}/_cancel?message_id=${curIdRef.current}`,
51
+ undefined
52
+ );
53
+ ```
54
+ 7. 需要每个聊天会话都有历史记录,历史记录包含用户输入和小助手回复
55
+ ```ts
56
+ const [_error, res] = await Get(`/chat/${chat?._id}/_history`, {
57
+ from: 0,
58
+ size: 1000,
59
+ });
60
+ response = res;
61
+ ```
62
+ 8. 需要打开聊天会话的方法,支持组件内部调用打开聊天会话
63
+ ```ts
64
+ const [_error, res] = await Post(`/chat/${chat?._id}/_open`, {});
65
+ response = res;
66
+ ```
67
+ 9. 需要关闭聊天会话的方法,支持组件内部调用关闭聊天会话
68
+ ```ts
69
+ const [_error, res] = await Post(`/chat/${chat?._id}/_close`, {});
70
+ response = res;
71
+ ```
72
+
73
+ ## 包含组件
74
+
75
+ 1. 独立历史列表组件(支持选择、重命名、删除、刷新、搜索)
76
+ 2. 独立小助手列表组件(支持选择、翻页、搜索)
77
+ 3. 独立 AI Chat 聊天组件(组件会话渲染 采用 "@infinilabs/chat-message": "workspace:*" 这个组件)
78
+
79
+ 外部用户使用的时候,可以自由拼装,自己根据需要选择使用哪个组件。
80
+
81
+