@matechat/ng 20.0.1-alpha.0 → 20.1.0-alpha.1

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.
Files changed (80) hide show
  1. package/README.md +206 -41
  2. package/fesm2022/matechat-ng.mjs +71 -70
  3. package/fesm2022/matechat-ng.mjs.map +1 -1
  4. package/index.d.ts +612 -3
  5. package/package.json +14 -3
  6. package/Base/base.component.d.ts +0 -11
  7. package/Bubble/avatar/avatar.component.d.ts +0 -23
  8. package/Bubble/avatar-body-icon/avatar-body-icon.component.d.ts +0 -7
  9. package/Bubble/avatar-no-body-icon/avatar-no-body-icon.component.d.ts +0 -7
  10. package/Bubble/bubble-loading/bubble-loading.component.d.ts +0 -5
  11. package/Bubble/bubble.component.d.ts +0 -26
  12. package/Bubble/bubble.module.d.ts +0 -10
  13. package/Bubble/index.d.ts +0 -6
  14. package/Input/button/button.component.d.ts +0 -32
  15. package/Input/index.d.ts +0 -2
  16. package/Input/input.component.d.ts +0 -65
  17. package/Input/input.module.d.ts +0 -11
  18. package/Input/send-icon/send-icon.component.d.ts +0 -5
  19. package/Locale/index.d.ts +0 -5
  20. package/Locale/locale.module.d.ts +0 -17
  21. package/Locale/locale.service.d.ts +0 -50
  22. package/Locale/translate.pipe.d.ts +0 -23
  23. package/MarkdownCard/code-block.component.d.ts +0 -49
  24. package/MarkdownCard/index.d.ts +0 -3
  25. package/MarkdownCard/markdown-card.component.d.ts +0 -200
  26. package/MarkdownCard/markdown-card.module.d.ts +0 -13
  27. package/components-common/Base/foundation.d.ts +0 -45
  28. package/components-common/Bubble/common/bubble-constants.d.ts +0 -4
  29. package/components-common/Bubble/common/bubble-types.d.ts +0 -12
  30. package/components-common/Bubble/foundation.d.ts +0 -9
  31. package/components-common/Input/button-foundation.d.ts +0 -15
  32. package/components-common/Input/common/types.d.ts +0 -16
  33. package/components-common/Input/foundation.d.ts +0 -20
  34. package/components-common/Locale/lang/en-us.d.ts +0 -26
  35. package/components-common/Locale/lang/zh-cn.d.ts +0 -26
  36. package/components-common/MarkdownCard/codeblock-foundation.d.ts +0 -21
  37. package/components-common/MarkdownCard/common/MDCardService.d.ts +0 -14
  38. package/components-common/MarkdownCard/common/MermaidService.d.ts +0 -23
  39. package/components-common/MarkdownCard/common/mdCard.types.d.ts +0 -56
  40. package/components-common/MarkdownCard/common/parser.d.ts +0 -150
  41. package/components-common/MarkdownCard/foundation.d.ts +0 -38
  42. package/esm2022/Base/base.component.mjs +0 -46
  43. package/esm2022/Bubble/avatar/avatar.component.mjs +0 -121
  44. package/esm2022/Bubble/avatar-body-icon/avatar-body-icon.component.mjs +0 -19
  45. package/esm2022/Bubble/avatar-no-body-icon/avatar-no-body-icon.component.mjs +0 -19
  46. package/esm2022/Bubble/bubble-loading/bubble-loading.component.mjs +0 -11
  47. package/esm2022/Bubble/bubble.component.mjs +0 -89
  48. package/esm2022/Bubble/bubble.module.mjs +0 -36
  49. package/esm2022/Bubble/index.mjs +0 -7
  50. package/esm2022/Input/button/button.component.mjs +0 -83
  51. package/esm2022/Input/index.mjs +0 -3
  52. package/esm2022/Input/input.component.mjs +0 -285
  53. package/esm2022/Input/input.module.mjs +0 -34
  54. package/esm2022/Input/send-icon/send-icon.component.mjs +0 -11
  55. package/esm2022/Locale/index.mjs +0 -6
  56. package/esm2022/Locale/locale.module.mjs +0 -39
  57. package/esm2022/Locale/locale.service.mjs +0 -140
  58. package/esm2022/Locale/translate.pipe.mjs +0 -38
  59. package/esm2022/MarkdownCard/code-block.component.mjs +0 -175
  60. package/esm2022/MarkdownCard/index.mjs +0 -4
  61. package/esm2022/MarkdownCard/markdown-card.component.mjs +0 -436
  62. package/esm2022/MarkdownCard/markdown-card.module.mjs +0 -44
  63. package/esm2022/components-common/Base/foundation.mjs +0 -66
  64. package/esm2022/components-common/Bubble/common/bubble-constants.mjs +0 -5
  65. package/esm2022/components-common/Bubble/common/bubble-types.mjs +0 -2
  66. package/esm2022/components-common/Bubble/foundation.mjs +0 -30
  67. package/esm2022/components-common/Input/button-foundation.mjs +0 -33
  68. package/esm2022/components-common/Input/common/types.mjs +0 -21
  69. package/esm2022/components-common/Input/foundation.mjs +0 -71
  70. package/esm2022/components-common/Locale/lang/en-us.mjs +0 -26
  71. package/esm2022/components-common/Locale/lang/zh-cn.mjs +0 -26
  72. package/esm2022/components-common/MarkdownCard/codeblock-foundation.mjs +0 -132
  73. package/esm2022/components-common/MarkdownCard/common/MDCardService.mjs +0 -69
  74. package/esm2022/components-common/MarkdownCard/common/MermaidService.mjs +0 -222
  75. package/esm2022/components-common/MarkdownCard/common/mdCard.types.mjs +0 -6
  76. package/esm2022/components-common/MarkdownCard/common/parser.mjs +0 -194
  77. package/esm2022/components-common/MarkdownCard/foundation.mjs +0 -84
  78. package/esm2022/matechat-ng.mjs +0 -5
  79. package/esm2022/public-api.mjs +0 -8
  80. package/public-api.d.ts +0 -4
package/README.md CHANGED
@@ -16,20 +16,20 @@
16
16
  - 多主题适配
17
17
  - 更多特性持续演进更新中...
18
18
 
19
- 了解更多请访问MateChat网站:[MateChat](https://matechat.gitcode.com)
19
+ 了解更多请访问 MateChat 网站:[MateChat](https://matechat.gitcode.com)
20
20
 
21
21
  ## 🖥️ 快速开始
22
22
 
23
23
  ### 1. 安装
24
24
 
25
- 如果你还没有新建项目,可以使用Angular CLI首先初始化一个`angular`项目:
25
+ 如果你还没有新建项目,可以使用 Angular CLI 首先初始化一个`angular`项目:
26
26
 
27
27
  ```bash
28
28
  $ npm install -g @angular/cli
29
29
 
30
- $ ng new matechat-ng
30
+ $ ng new matechat-demo
31
31
 
32
- $ npm i @matechat/ng @devui-design/icons
32
+ $ npm i @matechat/ng
33
33
  ```
34
34
 
35
35
  ### 2. 引入
@@ -37,61 +37,226 @@ $ npm i @matechat/ng @devui-design/icons
37
37
  在`app.component.ts`文件中引入模块
38
38
 
39
39
  ```ts
40
- import { Component } from '@angular/core';
41
- import { CommonModule } from '@angular/common';
42
- import { BubbleModule } from '@matechat/ng';
40
+ import { Component } from "@angular/core";
41
+ import { CommonModule } from "@angular/common";
42
+ import { BubbleModule } from "@matechat/ng";
43
43
 
44
44
  @Component({
45
- selector: 'app-root',
45
+ selector: "app-root",
46
46
  standalone: true,
47
- imports: [
48
- CommonModule,
49
- BubbleModule,
50
- ],
51
- templateUrl: './app.component.html',
52
- styleUrl: './app.component.css',
47
+ imports: [CommonModule, BubbleModule],
48
+ templateUrl: "./app.component.html",
49
+ styleUrl: "./app.component.css",
53
50
  })
54
- export class AppComponent {
55
- }
51
+ export class AppComponent {}
52
+ ```
53
+
54
+ ### 3. 使用
55
+
56
+ 在`app.component.html`文件中使用 MateChat 组件,如:
57
+
58
+ ```html
59
+ <mc-bubble [content]="'Hello, MateChat'" [avatarConfig]="{ name: 'matechat' }"></mc-bubble>
60
+ ```
61
+
62
+ 以下为一个简单的对话界面搭建示例:
63
+
64
+ ```html
65
+ <template>
66
+ <div class="chat-container">
67
+ <div class="chat-list">
68
+ <ng-container *ngFor="let msg of messages">
69
+ @if (msg.from === 'user') {
70
+ <mc-bubble class="user-bubble" [align]="'right'" [content]="msg.content"></mc-bubble>
71
+ } @else if (msg.from === 'model') {
72
+ <mc-bubble class="model-bubble" [align]="'left'">
73
+ <mc-markdown-card [content]="msg.content" [enableMermaid]="true"></mc-markdown-card>
74
+ </mc-bubble>
75
+ }
76
+ </ng-container>
77
+ </div>
78
+ <div class="chat-footer">
79
+ <mc-input (submit)="onSubmit($event)"></mc-input>
80
+ </div>
81
+ </div>
82
+ </template>
56
83
  ```
57
84
 
58
- 在`angular.json`中引入图标库样式文件
59
85
 
60
- ```json
61
- {
62
- "options": {
63
- "styles": [
64
- "node_modules/@devui-design/icons/icomoon/devui-icon.css"
65
- ],
66
- }
86
+ ```ts
87
+ import { Component } from '@angular/core';
88
+ import { CommonModule } from '@angular/common';
89
+ import { BubbleModule, InputModule, MarkdownCardModule } from '@matechat/ng';
90
+ @Component({
91
+ selector: 'app-root',
92
+ imports: [CommonModule, BubbleModule, InputModule, MarkdownCardModule],
93
+ templateUrl: './app.html',
94
+ styleUrl: './app.css',
95
+ })
96
+ export class App {
97
+ inputValue = '';
98
+ messages: any = [];
99
+
100
+ onSubmit = (evt: any) => {
101
+ this.inputValue = '';
102
+ // 用户发送消息
103
+ this.messages.push({
104
+ from: 'user',
105
+ content: evt,
106
+ });
107
+ setTimeout(() => {
108
+ // 模型返回消息
109
+ this.messages.push({
110
+ from: 'model',
111
+ content: evt,
112
+ });
113
+ }, 200);
114
+ };
67
115
  }
116
+
68
117
  ```
69
118
 
70
- ### 3. 使用
119
+ ```scss
120
+ .chat-container {
121
+ max-width: 1200px;
122
+ width: 100%;
123
+ padding: 12px;
124
+ border-radius: 8px;
125
+ margin: 0 auto;
126
+ border: 1px solid #e5e5e5;
127
+ }
128
+ .chat-list {
129
+ margin-bottom: 12px;
130
+ height: 500px;
131
+ overflow: auto;
132
+ }
133
+ .user-bubble,
134
+ .model-bubble {
135
+ display: block;
136
+ margin-top: 8px;
137
+ }
138
+ ```
139
+ ### 4. 主题化
71
140
 
72
141
  在`main.ts`中初始化主题
73
142
 
74
143
  ```ts
75
- import { bootstrapApplication } from '@angular/platform-browser';
76
- import { appConfig } from './app/app.config';
77
- import { AppComponent } from './app/app.component';
78
- import { ThemeServiceInit, infinityTheme } from 'devui-theme';
79
-
144
+ import { bootstrapApplication } from "@angular/platform-browser";
145
+ import { appConfig } from "./app/app.config";
146
+ import { AppComponent } from "./app/app.component";
147
+ import { ThemeServiceInit, infinityTheme } from "devui-theme";
148
+
80
149
  // 使用无限主题
81
- ThemeServiceInit({ infinityTheme }, 'infinityTheme');
82
- bootstrapApplication(AppComponent, appConfig)
83
- .catch((err) => console.error(err));
150
+ ThemeServiceInit({ infinityTheme }, "infinityTheme");
151
+ bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
152
+ ```
153
+ ## 🧩 对接模型服务
154
+
155
+ 在搭建完成页面后,可以开始对接模型服务,如 `盘古大模型`、`ChatGPT` 等优秀大模型,在注册并生成对应模型的调用API_Key后,可以参考如下方法进行调用:
156
+
157
+ 1. 通过 npm 安装 openai:
84
158
 
159
+ ```bash
160
+ $ npm install openai
85
161
  ```
86
162
 
87
- 在`app.component.html`文件中使用 MateChat 组件,如:
163
+ 2. 使用OpenAI初始化并调用模型接口,如下为一段代码示例:
164
+
165
+ ```js
166
+ import OpenAI from 'openai';
167
+
168
+ const client = new OpenAI({
169
+ apiKey: '', // 模型APIKey
170
+ baseURL: '', // 模型API地址
171
+ dangerouslyAllowBrowser: true,
172
+ });
173
+
174
+ const fetchData = (ques) => {
175
+ const completion = await client.chat.completions.create({
176
+ model: 'my-model', // 替换为自己的model名称
177
+ messages: [
178
+ { role: 'user', content: ques },
179
+ ],
180
+ stream: true, // 为 true 则开启接口的流式返回
181
+ });
182
+
183
+ for await (const chunk of completion) {
184
+ console.log('content: ', chunk.choices[0]?.delta?.content || '');
185
+ console.log('chatId: ', chunk.id);
186
+ }
187
+ }
188
+ ```
88
189
 
89
- ```html
90
- <template>
91
- <mc-bubble [content]="'Hello, MateChat'" [avatarConfig]="{ name: 'matechat' }"></mc-bubble>
92
- </template>
190
+ 那么参考以上步骤,【快速开始】中示例可调整下代码。
191
+
192
+ 将以下代码:
193
+
194
+ ```ts
195
+ onSubmit = (evt) => {
196
+ this.inputValue = '';
197
+ // 用户发送消息
198
+ this.messages.push({
199
+ from: 'user',
200
+ content: evt,
201
+ });
202
+ setTimeout(() => {
203
+ // 模型返回消息
204
+ this.messages.push({
205
+ from: 'model',
206
+ content: evt,
207
+ });
208
+ }, 200);
209
+ };
210
+ ```
211
+
212
+ 修改为:
213
+
214
+ ```ts
215
+ import OpenAI from 'openai';
216
+
217
+ client = new OpenAI({
218
+ apiKey: '', // 模型APIKey
219
+ baseURL: '', // 模型API地址
220
+ dangerouslyAllowBrowser: true,
221
+ });
222
+
223
+ onSubmit = async (evt) => {
224
+ this.inputValue = '';
225
+ // 用户发送消息
226
+ this.messages.push({
227
+ from: 'user',
228
+ content: evt,
229
+ avatarConfig: { name: 'user' },
230
+ });
231
+
232
+ this.fetchData(evt);
233
+ };
234
+
235
+ fetchData = async (ques) => {
236
+ this.messages.push({
237
+ from: 'model',
238
+ content: '',
239
+ avatarConfig: { name: 'model' },
240
+ id: '',
241
+ loading: true,
242
+ });
243
+ const completion = await this.client.chat.completions.create({
244
+ model: 'my-model', // 替换为自己的model名称
245
+ messages: [{ role: 'user', content: ques }],
246
+ stream: true, // 为 true 则开启接口的流式返回
247
+ });
248
+ for await (const chunk of completion) {
249
+ this.messages[this.messages.length - 1].loading = false;
250
+ const content = chunk.choices[0]?.delta?.content || '';
251
+ const chatId = chunk.id;
252
+ this.messages[this.messages.length - 1].content += content;
253
+ this.messages[this.messages.length - 1].id = chatId;
254
+ }
255
+ };
93
256
  ```
94
257
 
258
+ 完成模型API地址与APIKey填充后,即拥有了一个对接大模型的简单应用。如果你想要参考更完整的页面示例,可参考[演示场景](https://matechat.gitcode.com/vue-starter/)。
259
+
95
260
  ## 📝 提出意见&建议
96
261
 
97
262
  我们非常欢迎您的建议,您的每一个想法都可能帮助我们改进这个项目。如果您有任何关于功能改进、特性新增、文档补充或者其他方面的建议,随时在 [issues](https://gitcode.com/DevCloudFE/MateChat/issues) 提交。
@@ -111,11 +276,11 @@ MateChat 在不断的演进中,你可在这里了解我们的计划:[MateCha
111
276
 
112
277
  ## 🤝 欢迎贡献
113
278
 
114
- 我们诚挚地邀请您加入MateChat社区,一起参与项目的建设。无论您是经验丰富的开发者,还是刚刚起步的编程爱好者,您的贡献都对我们至关重要,这里是我们的[【贡献指南】](https://gitcode.com/DevCloudFE/MateChat/blob/main/CONTRIBUTING.md)。
279
+ 我们诚挚地邀请您加入 MateChat 社区,一起参与项目的建设。无论您是经验丰富的开发者,还是刚刚起步的编程爱好者,您的贡献都对我们至关重要,这里是我们的[【贡献指南】](https://gitcode.com/DevCloudFE/MateChat/blob/main/CONTRIBUTING.md)。
115
280
 
116
281
  ## 谁在使用
117
282
 
118
- [华为云CodeArts智能助手](https://www.huaweicloud.com/product/codeartside/snap.html)
283
+ [华为云 CodeArts 智能助手](https://www.huaweicloud.com/product/codeartside/snap.html)
119
284
 
120
285
  [InsCode AI IDE](https://inscode.csdn.net/)
121
286
 
@@ -125,4 +290,4 @@ MateChat 在不断的演进中,你可在这里了解我们的计划:[MateCha
125
290
 
126
291
  ## 联系方式
127
292
 
128
- 欢迎加入我们的开源社区,关注DevUI微信公众号:DevUI
293
+ 欢迎加入我们的开源社区,关注 DevUI 微信公众号:DevUI