@blueking/ai-blueking 0.2.13 → 0.2.15

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
@@ -6,6 +6,43 @@
6
6
  npm i @blueking/ai-blueking
7
7
  ```
8
8
 
9
+ ## 通过模板字符串渲染特定 html
10
+
11
+ #### 渲染知识库列表的模板
12
+
13
+ 可以使用类似如下的模板来渲染匹配的知识库列表
14
+
15
+ ```
16
+ <section class="knowledge-tips">
17
+ <i class="ai-blueking-icon ai-blueking-angle-up"></i>
18
+ <span class="knowledge-summary">
19
+ <i class="ai-blueking-icon ai-blueking-help-document"></i>
20
+ 引用 4 篇资料作为参考
21
+ </span>
22
+ <a href="xxx" target="_blank" class="knowledge-link">
23
+ 1. vivo 容器平台如何实现资源超卖方案
24
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
25
+ </a>
26
+ <a href="xxx" target="_blank" class="knowledge-link">
27
+ 1. vivo 容器平台如何实现资源超卖方案
28
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
29
+ </a>
30
+ <a href="xxx" target="_blank" class="knowledge-link">
31
+ 1. vivo 容器平台如何实现资源超卖方案
32
+ <i class="ai-blueking-icon ai-blueking-cc-jump-link"></i>
33
+ </a>
34
+ </section>
35
+ ```
36
+
37
+ #### 渲染带有点击交互的html
38
+
39
+ 可以使用类似如下的模板来渲染可点击交互的 html(具有'ai-clickable'的class),点击以后会触发组件的`ai-click`事件,并把 html 标签的`data-ai`的数据传递出来。这样业务可以进行二次处理。比如说把`data-ai`上的字符串赋值到输入框,可以使用`aiRef.value?.setInputMessage(val)`来设置输入框内容。
40
+
41
+ ```
42
+ <button data-ai="{ type: 'button', data: xxx }" class="ai-clickable">可点击的按钮</button>
43
+ <a data-ai="{ type: 'link', data: 'link url' }" class="ai-clickable" href="void">可点击的链接</a>
44
+ ```
45
+
9
46
  ## stream 模式
10
47
 
11
48
  不同框架,组件引入方式不同,具体可参考下面的的例子。这里使用 vue3 项目为例,来展示 stream 模式交互:
@@ -136,6 +173,7 @@ npm i @blueking/ai-blueking
136
173
  :scroll-loading-end="scrollLoadingEnd"
137
174
  :size-limit="sizeLimit"
138
175
  :start-position="startPosition"
176
+ @ai-click="handleAIClick"
139
177
  @choose-prompt="handleChoosePrompt"
140
178
  @clear="handleClear"
141
179
  @close="handleClose"
@@ -145,7 +183,7 @@ npm i @blueking/ai-blueking
145
183
  />
146
184
  </template>
147
185
  <script setup lang="ts">
148
- import { ref } from 'vue';
186
+ import { type ComponentInstance, ref } from 'vue';
149
187
 
150
188
  import AIBlueking, { type IPrompt, type IMessage, RoleType, MessageStatus } from '@blueking/ai-blueking';
151
189
 
@@ -226,6 +264,8 @@ npm i @blueking/ai-blueking
226
264
  // 向上滚动加载
227
265
  const scrollLoading = ref(false);
228
266
  const scrollLoadingEnd = ref(false);
267
+ // 组件实例
268
+ const aiRef = ref<ComponentInstance<typeof AIBlueking>>();
229
269
 
230
270
  const handleClear = () => {
231
271
  console.log('trigger clear');
@@ -270,6 +310,10 @@ npm i @blueking/ai-blueking
270
310
  const handleChoosePrompt = (prompt: IPrompt) => {
271
311
  console.log('choose prompt', prompt);
272
312
  };
313
+
314
+ const handleAIClick = (val: string) => {
315
+ aiRef.value?.setInputMessage(val);
316
+ };
273
317
  </script>
274
318
  ```
275
319
 
@@ -1,53 +1,40 @@
1
1
  import type { IMessage, IPrompt, IPositionLimit, ISize, IStartPosition, IModel } from './types';
2
- declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<{
2
+ interface IProps {
3
3
  messages: IMessage[];
4
- prompts?: IPrompt[] | undefined;
5
- loading?: boolean | undefined;
6
- headBackground?: string | undefined;
7
- background?: string | undefined;
8
- positionLimit?: IPositionLimit | undefined;
9
- sizeLimit?: ISize | undefined;
10
- startPosition?: IStartPosition | undefined;
11
- userPhoto?: string | undefined;
12
- name?: string | undefined;
13
- placeholder?: string | undefined;
14
- logo?: string | undefined;
15
- scrollLoading?: boolean | undefined;
16
- scrollLoadingEnd?: boolean | undefined;
17
- alert?: string | undefined;
18
- models?: IModel[] | undefined;
19
- model?: string | undefined;
20
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
4
+ prompts?: IPrompt[];
5
+ loading?: boolean;
6
+ headBackground?: string;
7
+ background?: string;
8
+ positionLimit?: IPositionLimit;
9
+ sizeLimit?: ISize;
10
+ startPosition?: IStartPosition;
11
+ userPhoto?: string;
12
+ name?: string;
13
+ placeholder?: string;
14
+ logo?: string;
15
+ scrollLoading?: boolean;
16
+ scrollLoadingEnd?: boolean;
17
+ alert?: string;
18
+ models?: IModel[];
19
+ model?: string;
20
+ }
21
+ declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<IProps>, {
22
+ setInputMessage: (val: string) => void;
23
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
21
24
  close: () => void;
22
25
  stop: () => void;
23
26
  clear: () => void;
24
27
  "scroll-load": () => void;
28
+ "ai-click": (val: string) => void;
25
29
  send: (val: string) => void;
26
30
  "update:model": (val: string) => void;
27
31
  "choose-prompt": (prompt: IPrompt) => void;
28
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<{
29
- messages: IMessage[];
30
- prompts?: IPrompt[] | undefined;
31
- loading?: boolean | undefined;
32
- headBackground?: string | undefined;
33
- background?: string | undefined;
34
- positionLimit?: IPositionLimit | undefined;
35
- sizeLimit?: ISize | undefined;
36
- startPosition?: IStartPosition | undefined;
37
- userPhoto?: string | undefined;
38
- name?: string | undefined;
39
- placeholder?: string | undefined;
40
- logo?: string | undefined;
41
- scrollLoading?: boolean | undefined;
42
- scrollLoadingEnd?: boolean | undefined;
43
- alert?: string | undefined;
44
- models?: IModel[] | undefined;
45
- model?: string | undefined;
46
- }>>> & {
32
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<IProps>>> & {
47
33
  "onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
48
34
  onClear?: (() => any) | undefined;
49
35
  onStop?: (() => any) | undefined;
50
36
  onSend?: ((val: string) => any) | undefined;
37
+ "onAi-click"?: ((val: string) => any) | undefined;
51
38
  "onScroll-load"?: (() => any) | undefined;
52
39
  onClose?: (() => any) | undefined;
53
40
  "onUpdate:model"?: ((val: string) => any) | undefined;
@@ -1,39 +1,34 @@
1
1
  import type { IMessage, IPrompt } from '../types/index';
2
- declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<{
2
+ interface IProps {
3
3
  messages: IMessage[];
4
- prompts?: IPrompt[] | undefined;
5
- loading?: boolean | undefined;
6
- background?: string | undefined;
7
- userPhoto?: string | undefined;
8
- placeholder?: string | undefined;
9
- scrollLoading?: boolean | undefined;
10
- scrollLoadingEnd?: boolean | undefined;
11
- alert?: string | undefined;
12
- }>, {
4
+ prompts?: IPrompt[];
5
+ loading?: boolean;
6
+ background?: string;
7
+ userPhoto?: string;
8
+ placeholder?: string;
9
+ scrollLoading?: boolean;
10
+ scrollLoadingEnd?: boolean;
11
+ alert?: string;
12
+ }
13
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
13
14
  background: string;
14
15
  scrollLoadingEnd: boolean;
15
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
16
+ }>, {
17
+ setInputMessage: (val: string) => void;
18
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
19
+ "ai-click": (userInput: string) => void;
16
20
  send: (userInput: string) => void;
17
21
  "choose-prompt": (prompt: IPrompt) => void;
18
22
  stop: () => void;
19
23
  "scroll-load": () => void;
20
- }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{
21
- messages: IMessage[];
22
- prompts?: IPrompt[] | undefined;
23
- loading?: boolean | undefined;
24
- background?: string | undefined;
25
- userPhoto?: string | undefined;
26
- placeholder?: string | undefined;
27
- scrollLoading?: boolean | undefined;
28
- scrollLoadingEnd?: boolean | undefined;
29
- alert?: string | undefined;
30
- }>, {
24
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<IProps>, {
31
25
  background: string;
32
26
  scrollLoadingEnd: boolean;
33
27
  }>>> & {
34
28
  "onChoose-prompt"?: ((prompt: IPrompt) => any) | undefined;
35
29
  onStop?: (() => any) | undefined;
36
30
  onSend?: ((userInput: string) => any) | undefined;
31
+ "onAi-click"?: ((userInput: string) => any) | undefined;
37
32
  "onScroll-load"?: (() => any) | undefined;
38
33
  }, {
39
34
  background: string;