ai-error-assistant-pro 0.0.25 → 0.0.27

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 (57) hide show
  1. package/components/demo/src/chat.vue +72 -5
  2. package/components/demo/src/error-chat.vue +65 -13
  3. package/dist/ai-error-assistant-pro.common.js +18663 -70
  4. package/dist/ai-error-assistant-pro.common.js.map +1 -1
  5. package/dist/ai-error-assistant-pro.css +1 -1
  6. package/dist/ai-error-assistant-pro.umd.js +18663 -70
  7. package/dist/ai-error-assistant-pro.umd.js.map +1 -1
  8. package/dist/ai-error-assistant-pro.umd.min.js +4 -4
  9. package/dist/ai-error-assistant-pro.umd.min.js.map +1 -1
  10. package/dist/fonts/KaTeX_AMS-Regular.1608a09b.woff +0 -0
  11. package/dist/fonts/KaTeX_AMS-Regular.4aafdb68.ttf +0 -0
  12. package/dist/fonts/KaTeX_AMS-Regular.a79f1c31.woff2 +0 -0
  13. package/dist/fonts/KaTeX_Caligraphic-Bold.cce5b8ec.ttf +0 -0
  14. package/dist/fonts/KaTeX_Caligraphic-Regular.07ef19e7.ttf +0 -0
  15. package/dist/fonts/KaTeX_Fraktur-Bold.9f256b85.woff +0 -0
  16. package/dist/fonts/KaTeX_Fraktur-Bold.b18f59e1.ttf +0 -0
  17. package/dist/fonts/KaTeX_Fraktur-Bold.d42a5579.woff2 +0 -0
  18. package/dist/fonts/KaTeX_Fraktur-Regular.7c187121.woff +0 -0
  19. package/dist/fonts/KaTeX_Fraktur-Regular.d3c882a6.woff2 +0 -0
  20. package/dist/fonts/KaTeX_Fraktur-Regular.ed38e79f.ttf +0 -0
  21. package/dist/fonts/KaTeX_Main-Bold.b74a1a8b.ttf +0 -0
  22. package/dist/fonts/KaTeX_Main-Bold.c3fb5ac2.woff2 +0 -0
  23. package/dist/fonts/KaTeX_Main-Bold.d181c465.woff +0 -0
  24. package/dist/fonts/KaTeX_Main-BoldItalic.6f2bb1df.woff2 +0 -0
  25. package/dist/fonts/KaTeX_Main-BoldItalic.70d8b0a5.ttf +0 -0
  26. package/dist/fonts/KaTeX_Main-BoldItalic.e3f82f9d.woff +0 -0
  27. package/dist/fonts/KaTeX_Main-Italic.47373d1e.ttf +0 -0
  28. package/dist/fonts/KaTeX_Main-Italic.8916142b.woff2 +0 -0
  29. package/dist/fonts/KaTeX_Main-Italic.9024d815.woff +0 -0
  30. package/dist/fonts/KaTeX_Main-Regular.0462f03b.woff2 +0 -0
  31. package/dist/fonts/KaTeX_Main-Regular.7f51fe03.woff +0 -0
  32. package/dist/fonts/KaTeX_Main-Regular.b7f8fe9b.ttf +0 -0
  33. package/dist/fonts/KaTeX_Math-BoldItalic.572d331f.woff2 +0 -0
  34. package/dist/fonts/KaTeX_Math-BoldItalic.a879cf83.ttf +0 -0
  35. package/dist/fonts/KaTeX_Math-BoldItalic.f1035d8d.woff +0 -0
  36. package/dist/fonts/KaTeX_Math-Italic.5295ba48.woff +0 -0
  37. package/dist/fonts/KaTeX_Math-Italic.939bc644.ttf +0 -0
  38. package/dist/fonts/KaTeX_Math-Italic.f28c23ac.woff2 +0 -0
  39. package/dist/fonts/KaTeX_SansSerif-Bold.8c5b5494.woff2 +0 -0
  40. package/dist/fonts/KaTeX_SansSerif-Bold.94e1e8dc.ttf +0 -0
  41. package/dist/fonts/KaTeX_SansSerif-Bold.bf59d231.woff +0 -0
  42. package/dist/fonts/KaTeX_SansSerif-Italic.3b1e59b3.woff2 +0 -0
  43. package/dist/fonts/KaTeX_SansSerif-Italic.7c9bc82b.woff +0 -0
  44. package/dist/fonts/KaTeX_SansSerif-Italic.b4c20c84.ttf +0 -0
  45. package/dist/fonts/KaTeX_SansSerif-Regular.74048478.woff +0 -0
  46. package/dist/fonts/KaTeX_SansSerif-Regular.ba21ed5f.woff2 +0 -0
  47. package/dist/fonts/KaTeX_SansSerif-Regular.d4d7ba48.ttf +0 -0
  48. package/dist/fonts/KaTeX_Script-Regular.03e9641d.woff2 +0 -0
  49. package/dist/fonts/KaTeX_Script-Regular.07505710.woff +0 -0
  50. package/dist/fonts/KaTeX_Script-Regular.fe9cbbe1.ttf +0 -0
  51. package/dist/fonts/KaTeX_Size1-Regular.fabc004a.ttf +0 -0
  52. package/dist/fonts/KaTeX_Size2-Regular.d6b476ec.ttf +0 -0
  53. package/dist/fonts/KaTeX_Size4-Regular.fbccdabe.ttf +0 -0
  54. package/dist/fonts/KaTeX_Typewriter-Regular.6258592b.woff +0 -0
  55. package/dist/fonts/KaTeX_Typewriter-Regular.a8709e36.woff2 +0 -0
  56. package/dist/fonts/KaTeX_Typewriter-Regular.d97aaf4a.ttf +0 -0
  57. package/package.json +2 -1
@@ -13,7 +13,7 @@
13
13
  </div>
14
14
  <div v-if ="list.type === 'user' && avatarUrl===''" class="robot user">user</div>
15
15
  <div :class="{'user-info': list.type === 'user'}" class="robot-message">
16
- <div v-html="list.message"></div>
16
+ <div v-html="renderFormulas(list.message)"></div>
17
17
  <div v-if="list.type === 'robot' && list.links.length > 0 && showFile" class="link">
18
18
  <div v-if="!list.allIdWithStart">
19
19
  <div class="link-title">参考文件</div>
@@ -90,6 +90,9 @@ import ChatTools from './chat-tools.vue';
90
90
  import ErrorChat from './error-chat.vue';
91
91
  import { marked } from 'marked';
92
92
  import { chartClear, sendMessageEventSource, getAutoQuestioning, pdfUrl, pdfUrlBase } from "../api";
93
+ import katex from 'katex';
94
+ import renderMathInElement from 'katex/contrib/auto-render/auto-render.js'
95
+ import 'katex/dist/katex.min.css';
93
96
  const controller = new AbortController();
94
97
  const signal = controller.signal;
95
98
 
@@ -158,7 +161,14 @@ export default {
158
161
  }
159
162
  },
160
163
  immediate: true
161
- }
164
+ },
165
+ messageData: {
166
+ handler() {
167
+ setTimeout(() => {
168
+ this.renderKaTeX();
169
+ })
170
+ }
171
+ }
162
172
  },
163
173
  methods: {
164
174
  handleScroll() {
@@ -401,6 +411,66 @@ export default {
401
411
  const baseUrl = `${pdfUrlBase}/#/pdf-view?documentUrl=${encodeURIComponent(url)}&pageIndex=${pageIndex}`;
402
412
  window.open(baseUrl, '_blank');
403
413
  },
414
+ renderFormulas(text) {
415
+ const {renderToString} = katex;
416
+ return text
417
+ .replace(/\$\$(.*?)\$\$/gs, (match) => {
418
+ try {
419
+ // 渲染块级公式
420
+ return renderToString(match.slice(2, -2), {displayMode: false});
421
+ } catch (error) {
422
+ console.error('Error rendering block formula:', error);
423
+ return match;
424
+ }
425
+ })
426
+ .replace(/\$.*?\$/g, (match) => {
427
+ match = match.replace(/<br>/g, '');
428
+ try {
429
+ // 渲染行内公式
430
+ return renderToString(match.slice(1, -1), {displayMode: false});
431
+ } catch (error) {
432
+ console.error('Error rendering inline formula:', error);
433
+ return match;
434
+ }
435
+ })
436
+ .replace(/\\\(.*?\\\)/g, (match) => {
437
+ try {
438
+ // 渲染行内公式
439
+ return renderToString(match.slice(2, -2), {displayMode: false});
440
+ } catch (error) {
441
+ console.error('Error rendering inline formula:', error);
442
+ return match;
443
+ }
444
+ })
445
+ .replace(/\\\[[\s\S]*?\\\]/g, (match) => {
446
+ match = match.replace(/<br>/g, '');
447
+ try {
448
+ // 渲染块级公式
449
+ return renderToString(match.slice(2, -2), {displayMode: false});
450
+ } catch (error) {
451
+ console.error('Error rendering block formula:', error);
452
+ return match;
453
+ }
454
+ });
455
+ },
456
+ renderKaTeX() {
457
+ setTimeout(() => {
458
+ // 自动渲染页面中的所有 KaTeX 公式
459
+ if (this.$refs.chatContainer) {
460
+ renderMathInElement(this.$refs.chatContainer, {
461
+ delimiters: [
462
+ {left: '$$', right: '$$', display: false},
463
+ {left: '\(', right: '\)', display: false},
464
+ {left: '\[', right: '\]', display: false}
465
+ ],
466
+ errorCallback() {
467
+ console.log('忽略错误')
468
+ },
469
+ ignoredClasses: ['link-content']
470
+ });
471
+ }
472
+ }, 50)
473
+ },
404
474
  },
405
475
  }
406
476
  </script>
@@ -484,9 +554,6 @@ export default {
484
554
  .robot-message {
485
555
  p {
486
556
  margin: 0;
487
- span {
488
- color: #fff !important;
489
- }
490
557
  }
491
558
  pre {
492
559
  code {
@@ -2,16 +2,16 @@
2
2
  <div class="error-chat-contain" @scroll="handleScroll">
3
3
  <div class="exercises-answer">
4
4
  <div class="exercises-answer-bg"></div>
5
- <p class="question-stem" v-html="questionStem.title"></p>
5
+ <p class="question-stem" v-html="renderFormulas(questionStem.title)"></p>
6
6
  <div class="answer-part" v-if="questionStem.type === 'single' || questionStem.type === 'multiple'">
7
7
  <div class="answer-list" v-for="(item, index) in questionStem.options" :key="index">
8
8
  <div class="check-content" style="width: 24px">
9
9
  <img src="../static/correct.png"
10
10
  v-if="questionStem.answer.indexOf(item) > -1"
11
11
  alt=""
12
- style="width: 24px">
12
+ style="width: 24px; height: 24px" />
13
13
  </div>
14
- <div class="answer-list" v-html="item"></div>
14
+ <div class="answer-list" v-html="renderFormulas(item)"></div>
15
15
  </div>
16
16
  </div>
17
17
  <div class="answer-part"
@@ -37,13 +37,13 @@
37
37
  </div>
38
38
  <div class="student-answer-part">
39
39
  <div class="check-content" style="width: 24px; margin-right: 16px">
40
- <img src="../static/error.png" style="width: 24px">
40
+ <img src="../static/error.png" style="width: 24px; height: 24px">
41
41
  </div>
42
42
  <div v-if="questionStem.type === 'single' || questionStem.type === 'multiple'">
43
43
  <div v-for="(item, index) in questionStem.studentAnswer"
44
44
  style="margin-right: 16px"
45
45
  :key="index"
46
- v-html="item">
46
+ v-html="renderFormulas(item)">
47
47
  </div>
48
48
  </div>
49
49
  <div v-if="questionStem.type === 'judge'">
@@ -64,9 +64,9 @@
64
64
  element-loading-text="分析中,请稍后"
65
65
  v-loading="!Object.keys(analysisData).length > 0">
66
66
  <div class="title-label">题目解析</div>
67
- <div class="answer-content" v-html="analysisData.analysis"></div>
67
+ <div class="answer-content" v-html="renderFormulas(analysisData.analysis)"></div>
68
68
  <div class="title-label">错因分析</div>
69
- <div class="answer-content" v-html="analysisData.reason"></div>
69
+ <div class="answer-content" v-html="renderFormulas(analysisData.reason)"></div>
70
70
  <div class="title-label" v-if="businessSource !== '2' && analysisData.recommend && analysisData.recommend.length > 0 && !allIdWithStart">
71
71
  推荐资料
72
72
  </div>
@@ -89,6 +89,8 @@
89
89
  <script>
90
90
  import ChatTools from './chat-tools.vue';
91
91
  import {erranalysis, pdfUrlBase, retryAnalysis} from '../api/index'
92
+ import katex from 'katex';
93
+ import 'katex/dist/katex.min.css';
92
94
  export default {
93
95
  name: 'ErrorChart',
94
96
  components: {
@@ -197,7 +199,49 @@ export default {
197
199
  this.analysisData = { key: true };
198
200
  console.log(e);
199
201
  }
200
- }
202
+ },
203
+ renderFormulas(text) {
204
+ const {renderToString} = katex;
205
+ return text
206
+ .replace(/\$\$(.*?)\$\$/gs, (match) => {
207
+ try {
208
+ // 渲染块级公式
209
+ return renderToString(match.slice(2, -2), {displayMode: false});
210
+ } catch (error) {
211
+ console.error('Error rendering block formula:', error);
212
+ return match;
213
+ }
214
+ })
215
+ .replace(/\$.*?\$/g, (match) => {
216
+ match = match.replace(/<br>/g, '');
217
+ try {
218
+ // 渲染行内公式
219
+ return renderToString(match.slice(1, -1), {displayMode: false});
220
+ } catch (error) {
221
+ console.error('Error rendering inline formula:', error);
222
+ return match;
223
+ }
224
+ })
225
+ .replace(/\\\(.*?\\\)/g, (match) => {
226
+ try {
227
+ // 渲染行内公式
228
+ return renderToString(match.slice(2, -2), {displayMode: false});
229
+ } catch (error) {
230
+ console.error('Error rendering inline formula:', error);
231
+ return match;
232
+ }
233
+ })
234
+ .replace(/\\\[[\s\S]*?\\\]/g, (match) => {
235
+ match = match.replace(/<br>/g, '');
236
+ try {
237
+ // 渲染块级公式
238
+ return renderToString(match.slice(2, -2), {displayMode: false});
239
+ } catch (error) {
240
+ console.error('Error rendering block formula:', error);
241
+ return match;
242
+ }
243
+ });
244
+ },
201
245
  }
202
246
  }
203
247
  </script>
@@ -228,13 +272,14 @@ export default {
228
272
  line-height: 24px;
229
273
  font-weight: 700;
230
274
  margin: 0;
275
+ }
231
276
 
232
- .question-stem img {
233
- max-width: 100%;
234
- height: auto;
235
- display: block;
236
- }
277
+ :deep(.question-stem img) {
278
+ width: 50%;
279
+ height: auto;
280
+ display: block;
237
281
  }
282
+
238
283
  .answer-part {
239
284
  margin-top: 24px;
240
285
  margin-left: 8px;
@@ -244,6 +289,13 @@ export default {
244
289
  margin-right: 16px;
245
290
  }
246
291
  }
292
+
293
+ :deep(.answer-part img) {
294
+ width: 50%;
295
+ height: auto;
296
+ display: block;
297
+ }
298
+
247
299
  .answer-list {
248
300
  display: flex;
249
301
  margin-bottom: 8px;