g-ai-robot3 0.1.90 → 0.1.92

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 CHANGED
@@ -1,115 +1,229 @@
1
- # g-ai-robot3数字人组件文档
1
+ # g-ai-robot3 数字人组件文档
2
2
 
3
3
  ## 简介
4
+
5
+ 封装了 QA 问答与语音问答能力,基于 Vue 3,可在业务中快速集成数字人对话体验。
6
+
7
+ ## 特性
8
+
9
+ - 支持文本问答与语音实时交互
10
+ - 可配置对话框主题、气泡、数字人画布与样式
11
+ - 内置工作流关键词触发
12
+ - 统一 API 前缀便于本地代理
13
+ ## 安装
14
+
15
+ ```bash
16
+ npm install g-ai-robot3 --save
4
17
  ```
5
- 封装了QA问答和语音问答功能(vue3版本)
18
+
19
+ ## 快速开始
20
+
21
+ 在入口文件中注册组件并引入样式:
22
+
23
+ ```ts
24
+ // main.ts
25
+ import GAiRobot3 from "g-ai-robot3";
26
+ import "g-ai-robot3/dist/index.css";
6
27
  ```
7
28
 
8
- ### 安装(npm or yarn)
29
+ 在页面中使用组件(最小必填配置):
30
+
31
+ ```vue
32
+ <template>
33
+ <GAiRobot3
34
+ :cozeInfo="{ bot_id: '7429224296222097443' }"
35
+ :apiPrefix="'/api21215'"
36
+ >
37
+ </GAiRobot3>
38
+ </template>
9
39
  ```
10
- npm install g-ai-robot3 --save
40
+
41
+ ## 高级示例:工作流与业务联动(富阳智能体使用示例)
42
+
43
+ ```vue
44
+ <script setup lang="ts">
45
+ import GAiRobot3 from "g-ai-robot3";
46
+ import "g-ai-robot3/dist/index.css";
47
+ import { ref, computed } from "vue";
48
+
49
+ const props = withDefaults(defineProps<{ eventFun: any[] }>(), {
50
+ eventFun: () => [],
51
+ });
52
+ const gAiRobot3Ref = ref<InstanceType<typeof GAiRobot3>>();
53
+
54
+ const aiEventFun = computed(() => {
55
+ return Object.assign(
56
+ [
57
+ // 自定义工作流事件,场景1
58
+ {
59
+ keywords: ["scene1_fuyangWeather"], // keywords的值是所配置的工作流名称
60
+ trigger: "before", // 固定值
61
+ fun: (params: any) => {
62
+ console.log("AI->富阳天气及山洪风险情况", params); // params是工作流的输出
63
+ // 在此触发你的业务逻辑,如切场景、更新看板等
64
+ },
65
+ },
66
+ // 自定义工作流事件,场景2
67
+ {
68
+ keywords: ["scene2"],
69
+ trigger: "before",
70
+ fun: () => {
71
+ // 触发文档弹窗或其它路由跳转
72
+ },
73
+ },
74
+ ],
75
+ props.eventFun
76
+ );
77
+ });
78
+ </script>
79
+
80
+ <template>
81
+ <GAiRobot3
82
+ ref="gAiRobot3Ref"
83
+ :isDebug="true"
84
+ :cozeInfo="{ bot_id: '7429224296222097443' }"
85
+ :apiPrefix="'/api21215'"
86
+ :eventFun="aiEventFun"
87
+ :canvasWidth="180"
88
+ :canvasHeight="180"
89
+ :videoStyle="{ width: '180px', visibility: 'hidden' }"
90
+ :digitalStyle="{ width: '180px', height: '180px' }"
91
+ :canvasStyle="{ width: '180px', height: '180px' }"
92
+ >
93
+ </GAiRobot3>
94
+ <!-- :isDebug 是否开启调试模式(打印语音输出、工作流返回值),默认值为false -->
95
+ <!-- :cozeInfo 智能体id,必填 -->
96
+ <!-- :apiPrefix API基础路径,可通过本地代理或环境变量覆盖,默认值为/api21215 -->
97
+ <!-- :canvasWidth 画布宽度,默认值为180 -->
98
+ <!-- :canvasHeight 画布高度,默认值为180 -->
99
+ <!-- :videoStyle 视频样式,默认值为{ width: '180px', visibility: 'hidden' } -->
100
+ <!-- :digitalStyle 数字人样式,默认值为{ width: '180px', height: '180px' } -->
101
+ <!-- :canvasStyle 画布样式,默认值为{ width: '180px', height: '180px' } -->
102
+ </template>
11
103
  ```
12
104
 
13
- ### 使用示例
14
- ``` javascript
15
- import gAiRobot from "g-ai-robot";
16
- import "g-ai-robot3/dist/g-ai-robot3.css";
105
+ ## 代理与跨域示例(Vite)
17
106
 
18
- <g-ai-robot :cozeInfo="{bot_id:'7429224296222097443'}" :apiPrefix="'/api21215'"
19
- :canvasWidth="180" :canvasHeight="180" :videoStyle="{width:'180px',visibility:'hidden'}" :digitalStyle="{width:'180px',height:'180px'}" :canvasStyle="{width:'180px',height:'180px'}"
20
- >
21
- </g-ai-robot>
107
+ ```ts
108
+ // vite.config.ts
109
+ export default defineConfig({
110
+ server: {
111
+ proxy: {
112
+ "/api21215": {
113
+ target: "http://your-backend-host",
114
+ changeOrigin: true,
115
+ rewrite: (path) => path.replace(/^\/api21215/, ""),
116
+ },
117
+ },
118
+ },
119
+ });
22
120
  ```
23
- ### 必填参数 (Required Parameters)
24
-
25
- | 参数 | 说明 | 类型 | 默认值 | 注意事项 |
26
- |--------------------|-----------------------|--------------|-----------------------------------------|--------------------------------------------------------------------------|
27
- | `cozeInfo` | 智能体配置 | object | `{bot_id:'7429224296222097443'}` | 必须替换为实际的bot_id |
28
- | `apiPrefix` | API基础路径 | string | `'/api21215'` | 可在项目中配置代理,默认值`'/api21215'`
29
- | `canvasWidth` | 画布宽度 | number | `180` | 必须与`videoStyle`和`digitalStyle`的宽度保持一致 |
30
- | `canvasHeight` | 画布高度 | number | `180` | 必须与`videoStyle`和`digitalStyle`的高度保持一致 |
31
- | `videoStyle` | 视频样式 | CSSProperties | `{width:'180px',visibility:'hidden'}` | width必须与`canvasWidth`保持一致 |
32
- | `digitalStyle` | 数字人样式 | CSSProperties | `{width:'180px',height:'180px'}` | width/height必须与`canvasWidth`/`canvasHeight`保持一致
33
- | `canvasStyle` | 数字人canvas宽高 | CSSProperties | `{width:'180px',height:'180px'}` | width/height必须与`canvasWidth`/`canvasHeight`保持一致
34
-
35
- ## 基础配置参数
36
-
37
- | 参数 | 说明 | 类型 | 默认值 |
38
- |---------------------|---------------------------------------|------------|-----------------------------------------|
39
- | `isDebug` | 是否开启调试模式(打印语音输出) | boolean | `false` |
40
- | `dialogBoxTheme` | 对话框主题 | string | `"light"` |
41
- | `suspensionStyle` | 对话框高度 | string | `"33vh"` |
42
- | `showMsgBubble` | 是否显示消息气泡 | boolean | `true` |
43
- | `isExhibitionPro` | 是否为数字展厅项目 | boolean | `false` |
44
- | `isShowDialogIcon` | 是否显示对话框图标 | boolean | `false` |
45
- | `stream` | 是否启用流式传输 | string | `"True"` |
46
- | `title` | 对话框标题 | string | `"GR水利大模型"` |
47
- | `greet` | 欢迎语 | string | `"您好,我是GR水利大模型智能小助手..."` |
48
- | `welcomeMessage` | 欢迎消息 | string | `"您好,我是GR水利大模型智能小助手..."` |
49
- | `waitTxt` | 等待提示文本 | string | `"贵仁科技AI正在生成回答"` |
50
- | `systemName` | 系统标识 | string | `"g-ai-robot3"` |
51
- | `placementBottom` | 对话框底部距离 | number | `100` |
52
- | `placementLeft` | 对话框左侧距离 | number | `450` |
53
- | `useAudio` | 是否启用音频功能 | boolean | `true` |
54
- | `space` | 监听间隔(ms) 已废弃 | number | `3000` |
55
- | `mode` | 交互模式,默认video,其他已废弃 | string | `"video"` |
56
-
57
- ### API 配置
58
-
59
- | 参数 | 说明 | 类型 | 默认值 |
60
- |---------------------------|--------------------------------|------------|-----------------------------------------|
61
- | `apiPrefix` | API基础路径,自定义跨域 | string | `'/api21215'` |
62
- | `createConversationUrl` | 创建会话接口 | string | `${apiPrefix}/chatGlm/createConversation` |
63
- | `wakeupAudio` | 音频打标接口 | string | `${apiPrefix}/asr/saveWakeUpAudio` |
64
- | `interrupt` | 中断请求接口 | string | `${apiPrefix}/chatGlm/cancelChat` |
65
- | `qaServer` | 问答服务接口 | string | `${apiPrefix}/chatGlm/searchTextNew` |
66
- | `audioWs` | 语音WebSocket服务 | string | `wss://model.keepsoft.net:39002/funasrWs` |
67
- | `voiceprintWs` | 声纹识别WebSocket服务 | string | `wss://model.keepsoft.net:39002/speakerWs` |
68
- | `instructWs` | 指令WebSocket服务(已废弃) | string | `wss://model.keepsoft.net:39002/commandWs` |
69
-
70
- ### 数字人配置
71
-
72
- | 参数 | 说明 | 类型 | 默认值 |
73
- |------------------------|--------------------------|--------------|----------------------------|
74
- | `videoStyle` | 视频样式 | CSSProperties | `{ width: "180px", visibility: "hidden" }` |
75
- | `digitalStyle` | 数字人样式 | CSSProperties | `{ width: "180px", height: "180px" }` |
76
- | `bubbleStyle` | 气泡样式 | CSSProperties | `{ width: "30%", height: "30%" }` |
77
- | `canvasWidth` | 画布宽度 | number | `300` |
78
- | `canvasHeight` | 画布高度 | number | `300` |
79
- | `canvasCartoonWidth` | 卡通形象宽度 | number | `200` |
80
- | `canvasCartoonHeight` | 卡通形象高度 | number | `320` |
81
- | `offer` | 数字人形象接口 | string | `${apiPrefix}/metahuman/offer` |
82
- | `humanaudio` | 数字人音频接口 | string | `${apiPrefix}/metahuman/humanaudio` |
83
- | `stop_audio` | 停止音频接口 | string | `${apiPrefix}/metahuman/stop_audio` |
84
- | `textDriven` | 文本驱动接口 | string | `${apiPrefix}/intelligentVoice/tts` |
85
-
86
- ### 消息气泡配置
87
-
88
- | 参数 | 说明 | 类型 | 默认值 |
89
- |--------------------|--------------------------|---------|---------|
90
- | `showMsgNumber` | 显示消息数量 | number | `5` |
91
- | `bubbleTheme` | 气泡主题 | string | `"dark"`|
92
- | `useCustomDialog` | 是否使用自定义对话框 | boolean | `false` |
93
- | `BubbleWidth` | 气泡宽度 | number | `220` |
94
- | `BubbleBottom` | 气泡底部距离 | number | `85` |
95
-
96
- ### 关键词触发事件,工作流处理
97
-
98
- ```typescript
121
+
122
+ ## 必填参数(Required)
123
+
124
+ | 参数 | 说明 | 类型 | 默认值 | 注意事项 |
125
+ | ----------- | ------------ | ------ | ------------------- | --------------------------------------- |
126
+ | `cozeInfo` | 智能体配置 | object | `{ bot_id: '...' }` | `bot_id`必须替换为实际的智能体 id |
127
+ | `apiPrefix` | API 基础路径 | string | `-` | 必须配置为你的代理前缀(如`/api21215`) |
128
+ | `apiPrefix` | API 基础路径 | string | `'/api21215'` | 可通过本地代理或环境变量覆盖 |
129
+ 说明:其他参数均有默认值,按需覆盖即可(建议保持数字人宽高与样式一致以避免拉伸)。
130
+ | `canvasHeight` | 画布高度 | number | `180` | 必须与 `videoStyle`、`digitalStyle.height` 一致 |
131
+ | `videoStyle` | 视频样式 | CSSProperties | `{ width: '180px', visibility: 'hidden' }` | `width` 与 `canvasWidth` 一致 |
132
+ | `digitalStyle` | 数字人样式 | CSSProperties | `{ width: '180px', height: '180px' }` | 与 `canvasWidth`/`canvasHeight` 保持一致 |
133
+ | `canvasStyle` | 画布样式 | CSSProperties | `{ width: '180px', height: '180px' }` | 与 `canvasWidth`/`canvasHeight` 保持一致 |
134
+
135
+ ## 基础配置
136
+
137
+ | 参数 | 说明 | 类型 | 默认值 |
138
+ | ------------------ | ------------------------------------ | ------- | -------------------------------------- |
139
+ | `isDebug` | 是否开启调试模式(打印语音输出) | boolean | `false` |
140
+ | `dialogBoxTheme` | 对话框主题 | string | `'light'` |
141
+ | `suspensionStyle` | 对话框高度 | string | `'33vh'` |
142
+ | `showMsgBubble` | 是否显示消息气泡 | boolean | `true` |
143
+ | `isExhibitionPro` | 是否为数字展厅项目 | boolean | `false` |
144
+ | `isShowDialogIcon` | 是否显示对话框图标 | boolean | `false` |
145
+ | `stream` | 是否启用流式传输 | string | `'True'` |
146
+ | `title` | 对话框标题 | string | `'GR水利大模型'` |
147
+ | `greet` | 欢迎语(文本对话框) | string | `'您好,我是GR水利大模型智能小助手...'` |
148
+ | `welcomeMessage` | 欢迎消息(气泡对话框) | string | `'您好,我是GR水利大模型智能小助手...'` |
149
+ | `waitTxt` | 等待提示文本 | string | `'贵仁科技AI正在生成回答'` |
150
+ | `systemName` | 系统标识 | string | `'g-ai-robot3'` |
151
+ | `placementBottom` | 对话框底部距离 | number | `100` |
152
+ | `placementLeft` | 对话框左侧距离 | number | `450` |
153
+ | `useAudio` | 是否启用音频功能 | boolean | `true` |
154
+ | `space` | 监听间隔(ms)已废弃 | number | `3000` |
155
+ | `mode` | 交互模式(默认 `video`,其他已废弃) | string | `'video'` |
156
+
157
+ ## API 配置
158
+
159
+ | 参数 | 说明 | 类型 | 默认值 |
160
+ | ----------------------- | ----------------------------- | ------ | ------------------------------------------ |
161
+ | `apiPrefix` | API 基础路径(可自定义跨域) | string | `'/api21215'` |
162
+ | `createConversationUrl` | 创建会话接口 | string | `${apiPrefix}/chatGlm/createConversation` |
163
+ | `wakeupAudio` | 音频打标接口 | string | `${apiPrefix}/asr/saveWakeUpAudio` |
164
+ | `interrupt` | 中断请求接口 | string | `${apiPrefix}/chatGlm/cancelChat` |
165
+ | `qaServer` | 问答服务接口 | string | `${apiPrefix}/chatGlm/searchTextNew` |
166
+ | `audioWs` | 语音 WebSocket 服务 | string | `wss://model.keepsoft.net:39002/funasrWs` |
167
+ | `voiceprintWs` | 声纹识别 WebSocket 服务 | string | `wss://model.keepsoft.net:39002/speakerWs` |
168
+ | `instructWs` | 指令 WebSocket 服务(已废弃) | string | `wss://model.keepsoft.net:39002/commandWs` |
169
+
170
+ ## 数字人配置
171
+
172
+ | 参数 | 说明 | 类型 | 默认值 |
173
+ | --------------------- | -------------- | ------------- | ------------------------------------------ |
174
+ | `videoStyle` | 视频样式 | CSSProperties | `{ width: '180px', visibility: 'hidden' }` |
175
+ | `digitalStyle` | 数字人样式 | CSSProperties | `{ width: '180px', height: '180px' }` |
176
+ | `bubbleStyle` | 气泡样式 | CSSProperties | `{ width: '30%', height: '30%' }` |
177
+ | `canvasWidth` | 画布宽度 | number | `180` |
178
+ | `canvasHeight` | 画布高度 | number | `180` |
179
+ | `canvasCartoonWidth` | 卡通形象宽度 | number | `200` |
180
+ | `canvasCartoonHeight` | 卡通形象高度 | number | `320` |
181
+ | `offer` | 数字人形象接口 | string | `${apiPrefix}/metahuman/offer` |
182
+ | `humanaudio` | 数字人音频接口 | string | `${apiPrefix}/metahuman/humanaudio` |
183
+ | `stop_audio` | 停止音频接口 | string | `${apiPrefix}/metahuman/stop_audio` |
184
+ | `textDriven` | 文本驱动接口 | string | `${apiPrefix}/intelligentVoice/tts` |
185
+
186
+ ## 消息气泡配置
187
+
188
+ | 参数 | 说明 | 类型 | 默认值 |
189
+ | ----------------- | -------------------- | ------------- | ----------------------------------- |
190
+ | `showMsgNumber` | 显示消息数量 | number | `5` |
191
+ | `bubbleTheme` | 气泡主题 | string | `'dark'` |
192
+ | `useCustomDialog` | 是否使用自定义对话框 | boolean | `false` |
193
+ | `BubbleWidth` | 气泡容器样式 | CSSProperties | `{ width: '220px', bottom: '85%' }` |
194
+ | `BubbleWidth` | 气泡宽度 | number | `220` |
195
+ | `BubbleBottom` | 气泡底部距离 | number | `85` |
196
+ - 组件会将后端返回的关联问题(如 `questions` 列表)整合为可点击项,点击后自动填充并发送。
197
+
198
+ 用途:引导用户进行更深入或相关的追问,提升对话效率。
199
+
200
+ ## 关键词触发事件(工作流)
201
+
202
+ ```ts
99
203
  eventFun: [
100
204
  {
101
- keywords: ["打开灌区"], // 触发关键词
102
- trigger: "after", // 触发时机: before/after/together
103
- fun: (a: any) => { // 回调函数
104
- console.log("打开灌区");
105
- }
205
+ keywords: ["打开灌区"], // 触发关键词,关键词为工作流名称
206
+ trigger: "after", // 触发时机,after 表示在 AI 回答后触发
207
+ fun: (a: any) => {
208
+ console.log("打开灌区",a); // a为工作流设置的返回内容
209
+ },
106
210
  },
107
211
  {
108
212
  keywords: ["打开技术舱"],
109
213
  trigger: "after",
110
214
  fun: (a: any) => {
111
- console.log("打开技术舱");
112
- }
113
- }
114
- ]
115
- ```
215
+ console.log("打开技术舱",a);
216
+ },
217
+ },
218
+ ];
219
+ ```
220
+
221
+ ## 常见问题
222
+
223
+ - 画布或视频尺寸不一致:请确保 `canvasWidth/canvasHeight` 与 `videoStyle/digitalStyle/canvasStyle` 一致。
224
+ - 音频或 WS 连接失败:检查 `audioWs/voiceprintWs` 地址可达性。
225
+ - 问答接口超时:确认 `apiPrefix` 代理转发配置正确。
226
+
227
+ ## 许可证
228
+
229
+ 本项目遵循仓库中的 `LICENSE` 许可。
@@ -91907,8 +91907,8 @@ const DC = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzN2IzODNlNzZiMmU0NGNmOTQ5ODg2YjY1NjI
91907
91907
  humanaudio: { default: (t) => `${t.apiPrefix}/metahuman/humanaudio` },
91908
91908
  stop_audio: { default: (t) => `${t.apiPrefix}/metahuman/stop_audio` },
91909
91909
  textDriven: { default: (t) => `${t.apiPrefix}/intelligentVoice/tts` },
91910
- canvasWidth: { default: 300 },
91911
- canvasHeight: { default: 300 },
91910
+ canvasWidth: { default: 180 },
91911
+ canvasHeight: { default: 180 },
91912
91912
  canvasCartoonWidth: { default: 200 },
91913
91913
  canvasCartoonHeight: { default: 320 },
91914
91914
  showMsgNumber: {},
@@ -92347,7 +92347,7 @@ const DC = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzN2IzODNlNzZiMmU0NGNmOTQ5ODg2YjY1NjI
92347
92347
  for (const [l, n] of e)
92348
92348
  a[l] = n;
92349
92349
  return a;
92350
- }, Mft = /* @__PURE__ */ rL(Tft, [["__scopeId", "data-v-fc8faaf3"]]), UC = {};
92350
+ }, Mft = /* @__PURE__ */ rL(Tft, [["__scopeId", "data-v-5f80cf12"]]), UC = {};
92351
92351
  function Kft(t) {
92352
92352
  let e = UC[t];
92353
92353
  if (e)