lke-component 1.0.125-beta.4

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,223 @@
1
+ # lke-component
2
+
3
+ npm install lke-component@^1.0.92
4
+
5
+ 提供三个组件:LkeMsg、MsgContent、MsgLoading
6
+
7
+ npm install lke-utils@^0.0.4
8
+
9
+ 提供一个小程序环境的转换方法: getMarkdownHtml
10
+
11
+
12
+ 组件使用说明:
13
+
14
+ MsgLoading: 展示模型加载中的状态
15
+
16
+ ```
17
+ props:
18
+ loadingIcon: String, // 消息的ICON,如果有话显示Icon,没有的话不会显示Icon
19
+ loadingMessage: Boolean, // 是否处于加载中
20
+ loadingText: String, // 加载中的消息内容
21
+ transferStatus: Boolean // 转人工状态
22
+ ```
23
+
24
+ MsgContent: 展示MD内容
25
+
26
+ ```
27
+ props:
28
+ content: String, // MD消息
29
+ isFinal: Boolean, // 消息是否输出结束
30
+ loadingMessage: Boolean, // 是否加载中
31
+ isMdExpand: Boolean, // 是否展开所有的消息
32
+ isReplaceLinks: Boolean, // 是否替换链接为第三方提示
33
+ isPrintAnimate: Boolean, // 是否显示打字的图标
34
+ styleObj: Object, // MD消息体的style
35
+ clazzTable: String, // MD消息体的 table 样式 (后面会加上默认统一样式),props方便修改
36
+ clazzMd: String, // MD消息体的class
37
+ anchorAttributes: Object, // vue-markdown 的props透传,见示例
38
+ linkify: Boolean // vue-markdown 的props透传,见示例
39
+ ```
40
+
41
+ LkeMsg: 两个组件的聚合态
42
+
43
+ ```
44
+ props:
45
+ LoadingIcon: String, // 加载中的图标CDN地址,如果没有传的话,默认不显示图标
46
+ type: String, // 当前消息的类型,type透传,一般为 reply 、 token_stat
47
+ isReplaceLinks: Boolean, // 是否替换为大模型的第三方链接提示
48
+ showProcedures: Boolean, // 是否显示模型输出的状态
49
+ isPrintAnimate: Boolean, // 是否显示打字效果
50
+ transferStatus: Boolean, // 转人工状态
51
+ clazz: String, //外层包裹的div的类名
52
+ item: Object, // 当前的消息内容
53
+ styleObj: Object, // MD消息体的style
54
+ clazzTable: String, // MD消息体的 table 样式 (后面会加上默认统一样式),props方便修改, 组件自带默认样式:table-style、table
55
+ clazzMd: String, // MD消息体的class, 组件自带默认样式:answer-md
56
+ anchorAttributes: Object, // vue-markdown 的props透传,见示例
57
+ linkify: Boolean //vue-markdown 的props透传,见示例
58
+ printCount: Number | undefined //每次打印的字数用于控制时间
59
+ hideCursorPoint: Boolean | undefined //是否显示打印的图标
60
+ ```
61
+
62
+ MsgThought: 显示deepseek 的思考内容
63
+
64
+ ```
65
+ props:
66
+ content: String \\ 思考内容
67
+ title: String \\ 标题,如“思考完成"
68
+ titleIcon: String \\ 图标小图标icon 大小16x16px
69
+ nodeName: String \\ 可不填,如”deepseek“
70
+ status: String \\ 思考状态,可选值'success', 'failed', 'processing', 'stop'
71
+ elapsed: number \\ 思考花费时间, 毫秒,如17485
72
+ ```
73
+
74
+ 在vue项目里使用
75
+ 1. install方式引入
76
+
77
+ ```
78
+ // 在vue的入口文件引入组件库
79
+ import lkeComponent from 'lke-component';
80
+ Vue.use(lkeComponent);
81
+
82
+
83
+ // 在对应的vue页面里面使用组件
84
+
85
+ <!-- Loading切换 + Markdown渲染 -->
86
+ <LkeMsg :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" :isReplaceLinks="true" :content="item.content" :isFinal="item.is_final" :isMdExpand="item.isMdExpand" :clazzMd="`question-text ${webIMSource === 'client' && isMobile ? 'question-text-mobile' : ''}`" :styleObj="{ 'max-width': webIMSource === 'client' && isMobile ? '352px' : '680px' }" />
87
+
88
+ <!-- 非转人工情况下, 展示临时[正在思考中]消息 -->
89
+ <MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
90
+
91
+
92
+ <!-- deepseek 思考内容渲染 -->
93
+ <MsgThought
94
+ :content="思考内容"
95
+ :title="思考标题"
96
+ :titleIcon="test.png"
97
+ :nodeName="deepseek"
98
+ :status="success"
99
+ :elapsed="17485"
100
+ />
101
+
102
+ <!-- Markdown渲染 -->
103
+ <MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" :isMdExpand="item.isMdExpand" :clazzMd="`question-text ${webIMSource === 'client' && isMobile ? 'question-text-mobile' : ''}`" :styleObj="{ 'max-width': webIMSource === 'client' && isMobile ? '352px' : '680px' }" :isPrintAnimate="true" :printCount="1" :hideCursorPoint="true"/>
104
+ ```
105
+
106
+ 2. import方式引入
107
+ ```
108
+ // 在需要使用此组件的vue文件,比如component.vue中引入
109
+ import { MsgLoading, MsgContent } from 'lke-component';
110
+
111
+ // components中注册此组件
112
+ export default {
113
+ components: {
114
+ MsgContent,
115
+ MsgLoading,
116
+ }
117
+ }
118
+
119
+ // 在template标签中使用
120
+ <MsgLoading :loadingIcon="loadingIcon" :loadingMessage="item.loading_message" :loadingText="item.text" :transferStatus="transferStatus" />
121
+
122
+
123
+ <!-- Markdown渲染 -->
124
+ <MsgContent :isReplaceLinks="true" :loadingMessage="item.loading_message" :content="item.content" :isFinal="item.is_final" :isMdExpand="item.isMdExpand" :clazzMd="`question-text ${webIMSource === 'client' && isMobile ? 'question-text-mobile' : ''}`" :styleObj="{ 'max-width': webIMSource === 'client' && isMobile ? '352px' : '680px' }" />
125
+ ```
126
+
127
+
128
+ 小程序转换方法使用说明:
129
+
130
+ getMarkdownHtml 提供一个方法,传入MD格式的字符串,返回Html格式的字符串。
131
+
132
+
133
+
134
+ import { getMarkdownHtml } from 'lke-utils';
135
+
136
+ ```
137
+ /**
138
+ * 传入MD格式的字符串,返回Html格式的字符串
139
+ * @param {String} markdownStr markdown字符串
140
+ * @param {Boolean} isMsgComplete 是否最终的消息
141
+ * @param {Object} marked 引入 marked-it 返回的marked对象:import { marked } from '@/utils/marked.min.js';
142
+ * @returns {String} html字符串
143
+ */
144
+ getMarkdownHtml(markdownStr, isMsgComplete, marked = null)
145
+ ```
146
+
147
+
148
+ ### 在react组件中使用
149
+ ```
150
+ import { MsgContent, MsgThought } from "lke-component/react";
151
+ import "lke-component/css";
152
+
153
+ const App = () => {
154
+ const [list, setList] = useState([{
155
+ content: "天气不错哦<b>?</b>",
156
+ isFinal: true, // 消息是否输出结束
157
+ loadingMessage: false, // 是否加载中
158
+ isMdExpand: false, // 是否展开所有的消息
159
+ isReplaceLinks: false, // 是否替换链接为第三方提示
160
+ isPrintAnimate: false, // 是否显示打字的效果
161
+ styleObj: {}, // MD消息体的style
162
+ clazzTable: '', // MD消息体的 table 样式
163
+ clazzMd: '', // MD消息体的类名
164
+ anchorAttributes: {}, // 为链接添加自定义属性,如{target: '_blank'}
165
+ id: 1,
166
+ linkify: false // markdown-it 的props透传
167
+ thoughts: [{
168
+ title: "思考完成", // 标题
169
+ titleIcon: 'test.png', // 标题旁的icon,后端一般返回 emoji 图标地址
170
+ nodeName: "deepseek", // 非必传,显示大模型名称
171
+ status: "success", // 思考状态,用来显示不同状态 icon
172
+ detailVisible: true, // 控制思考内容区域是否显示,配合onTitleClick,可以控制思考内容展开和收起
173
+ elapsed: 17485, // 思考时间,单位 ms
174
+ content: ` // // 思考内容
175
+ 好的,我现在需要处理用户的问题“你好”,并根据提供的搜索结果生成一个回答,同时正确引用来源。首先,用户的问题是一个常见的问候语,所以答案应该解释“你好”的含义和用法。
176
+
177
+ 看一下搜索结果的各个条目。结果1到4、7、8都是关于“你好”这个词语的解释,包括它的拼音、用法、近义词等。而结果5、6、9是关于韩国电影《你好》的信息,和用户的问题无关,可以忽略。
178
+
179
+ 接下来,我需要从相关的结果中提取关键信息。例如,结果1提到“你好”是用于礼貌的打招呼或问候,适用于非熟人群体。结果2和3也给出了类似的解释,并指出它是汉语中的常用敬语。结果4详细介绍了“你好”的不同解释,包括网络解释和基础解释。结果7和8补充了其作为打招呼的敬语用法。
180
+
181
+ 需要将这些信息整合成一个连贯的回答,并用正确的引用标注。例如,综合结果1、2、3、4、7、8的内容,说明“你好”的基本含义、用法以及适用场合。注意不要提到电影相关的信息,因为与问题无关。
182
+
183
+ 最后,确保回答简洁明了,使用中文口语化表达,避免使用Markdown格式,并在适当的位置添加引用,如[1](@ref)、[2](@ref)等。同时,根据当前时间2025年2月19日,用户的问题只是问候,不需要时间相关的调整,所以直接回答即可。
184
+ `,
185
+ }]
186
+ }]);
187
+
188
+ return (
189
+ <div className="main">
190
+ {list.map((item, index) => (
191
+ <div>
192
+ {item.thoughts.map((thought, index) => (
193
+ <MsgThought
194
+ key={index}
195
+ detailVisible={thought.detailVisible}
196
+ content={thought.content}
197
+ title={thought.title}
198
+ titleIcon={thought.titleIcon}
199
+ nodeName={thought.nodeName}
200
+ status={thought.status}
201
+ elapsed={thought.elapsed}
202
+ onTitleClick={() => void 0}
203
+ />
204
+ ))}
205
+ </div>
206
+ <MsgContent
207
+ key={id}
208
+ content={item.content}
209
+ isFinal={item.isFinal}
210
+ styleObj={item.styleObj}
211
+ clazzTable={item.clazzTable}
212
+ clazzMd={item.clazzMd}
213
+ anchorAttributes={item.anchorAttributes}
214
+ linkify={item.linkify}
215
+ isPrintAnimate={item.isPrintAnimate}
216
+ isReplaceLinks={item.isReplaceLinks}
217
+ isMdExpand={item.isMdExpand}
218
+ />
219
+ ))}
220
+ </div>
221
+ );
222
+ }
223
+ ```
package/dist/demo.html ADDED
@@ -0,0 +1,8 @@
1
+ <meta charset="utf-8">
2
+ <title>lke-component demo</title>
3
+ <script src="./lke-component.umd.js"></script>
4
+
5
+
6
+ <script>
7
+ console.log(lke-component)
8
+ </script>