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