ai-question-pro 0.0.22 → 0.0.24

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.
@@ -9,41 +9,41 @@
9
9
  <img src="../static/logo.png" alt="" style="width: 32px; height: 18px;"/>
10
10
  <span>出题</span>
11
11
  </div>
12
- <div class="ai-bot-switch-wrap" style="position: absolute; left: 120px">
13
- <div class="ai-bot-switch" @click="dropdownVisible = !dropdownVisible">
14
- <img src="../static/aiBot-icon.png" alt="" style="width: 24px; height: 24px">
15
- <span class="ai-bot-label">
16
- {{ currentBot === 'course' ? '课程智能体' : '通义千问' }}
17
- </span>
18
- <img src="../static/check-icon.png" alt="" style="width: 12px; height: 12px">
19
- </div>
20
- <div
21
- v-if="dropdownVisible"
22
- class="ai-bot-dropdown"
23
- @mousedown.prevent
24
- style="position: absolute; z-index: 1000; min-width: 20%;"
25
- >
26
- <div
27
- class="ai-bot-dropdown-item"
28
- :class="{ active: currentBot === 'tongyi' }"
29
- @click="selectBot('tongyi')"
30
- >通义千问
31
- </div>
12
+ <!-- <div class="ai-bot-switch-wrap" style="position: absolute; left: 120px">-->
13
+ <!-- <div class="ai-bot-switch" @click="dropdownVisible = !dropdownVisible">-->
14
+ <!-- <img src="../static/aiBot-icon.png" alt="" style="width: 24px; height: 24px">-->
15
+ <!-- <span class="ai-bot-label">-->
16
+ <!-- {{ currentBot === 'course' ? '课程智能体' : '通义千问' }}-->
17
+ <!-- </span>-->
18
+ <!-- <img src="../static/check-icon.png" alt="" style="width: 12px; height: 12px">-->
19
+ <!-- </div>-->
20
+ <!-- <div-->
21
+ <!-- v-if="dropdownVisible"-->
22
+ <!-- class="ai-bot-dropdown"-->
23
+ <!-- @mousedown.prevent-->
24
+ <!-- style="position: absolute; z-index: 1000; min-width: 20%;"-->
25
+ <!-- >-->
32
26
  <!-- <div-->
33
- <!-- v-if="courseId"-->
34
27
  <!-- class="ai-bot-dropdown-item"-->
35
- <!-- :class="{ active: currentBot === 'course' }"-->
36
- <!-- @click="selectBot('course')"-->
37
- <!-- >课程智能体-->
28
+ <!-- :class="{ active: currentBot === 'tongyi' }"-->
29
+ <!-- @click="selectBot('tongyi')"-->
30
+ <!-- >通义千问-->
38
31
  <!-- </div>-->
39
- </div>
40
- </div>
32
+ <!--&lt;!&ndash; <div&ndash;&gt;-->
33
+ <!--&lt;!&ndash; v-if="courseId"&ndash;&gt;-->
34
+ <!--&lt;!&ndash; class="ai-bot-dropdown-item"&ndash;&gt;-->
35
+ <!--&lt;!&ndash; :class="{ active: currentBot === 'course' }"&ndash;&gt;-->
36
+ <!--&lt;!&ndash; @click="selectBot('course')"&ndash;&gt;-->
37
+ <!--&lt;!&ndash; >课程智能体&ndash;&gt;-->
38
+ <!--&lt;!&ndash; </div>&ndash;&gt;-->
39
+ <!-- </div>-->
40
+ <!-- </div>-->
41
41
  </template>
42
42
  <div class="add_question_body">
43
43
  <div class="question-type-header">
44
44
  <span class="required-mark">*</span>
45
45
  <span class="section-title">题目类型:</span>
46
- <span class="tip-text">(为避免您等待时间过长,一次性最多生成10道题)</span>
46
+ <span class="tip-text">(为避免您等待时间过长,所选择题型数量总和最好不超过10道</span>
47
47
  </div>
48
48
 
49
49
  <!-- 题目类型列表 -->
@@ -299,7 +299,7 @@ export default {
299
299
  {name: '简答题', id: 'shortanswer'},
300
300
  ],
301
301
  difficultyList: [
302
- {name: '超级简单', id: 0},
302
+ {name: '非常简单', id: 0},
303
303
  {name: '简单', id: 1},
304
304
  {name: '一般', id: 2},
305
305
  {name: '困难', id: 3},
@@ -314,6 +314,8 @@ export default {
314
314
  joinedQuestions: [], // 存储已加入题库的题目索引
315
315
  retryCountMap: {}, // 存储每个题目的重试次数
316
316
  isGenerating: false, // 内部loading状态
317
+ typeGeneratedCounts: {}, // 跟踪每个题型已生成的数量
318
+ pendingGenerations: [], // 待生成的题目队列
317
319
  }
318
320
  },
319
321
  watch: {
@@ -448,6 +450,16 @@ export default {
448
450
  return this.$message.warning('请至少选择一种题目类型')
449
451
  }
450
452
 
453
+ // 验证选中的题目类型是否都输入了数量
454
+ for (let type of selectedTypes) {
455
+ const count = this.form.typeCounts[type]
456
+ if (!count || count <= 0) {
457
+ const found = this.quesTypeList.find(item => item.id === type);
458
+ const typeName = (found && found.name) || type;
459
+ return this.$message.warning(`请为${typeName}输入生成数量`)
460
+ }
461
+ }
462
+
451
463
  // 验证是否选择了知识点
452
464
  if (!this.form.knowledgeIds) {
453
465
  return this.$message.warning('请选择关联知识点')
@@ -501,39 +513,119 @@ export default {
501
513
  });
502
514
  },
503
515
 
504
- reSend() {
516
+ // 重新生成失败的题目 - 需要指定具体的题型和难度
517
+ reSend(failedQuestionType = null, failedDifficulty = null) {
505
518
  this.isGenerating = true;
519
+
520
+ // 如果没有指定失败的题型,则需要分析哪个题型还缺少题目
521
+ let targetType = failedQuestionType;
522
+ let targetDifficulty = failedDifficulty;
523
+
524
+ if (!targetType) {
525
+ // 分析哪个题型的数量不足
526
+ const selectedTypes = Object.keys(this.form.selectedTypes).filter(key => this.form.selectedTypes[key]);
527
+ for (let type of selectedTypes) {
528
+ const expectedCount = this.form.typeCounts[type];
529
+ const actualCount = this.typeGeneratedCounts[type] || 0;
530
+ if (actualCount < expectedCount) {
531
+ targetType = type;
532
+ targetDifficulty = this.form.typeDifficulties[type];
533
+ break;
534
+ }
535
+ }
536
+ }
537
+
538
+ // 如果找不到需要补充的题型,说明数量已经足够
539
+ if (!targetType) {
540
+ this.isGenerating = false;
541
+ return;
542
+ }
543
+
544
+ // 使用 generateSingleQuestion 方法来生成指定题型
545
+ this.generateSingleQuestion(targetType, targetDifficulty);
546
+ },
547
+
548
+ //发送请求
549
+ sendPost() {
550
+ checkVersion(this.businessSource).then(res => {
551
+ console.log(res);
552
+ if (res.errCode === '403') {
553
+ this.$message.warning(res.errMessage)
554
+ } else {
555
+ this.postQuestion();
556
+ }
557
+ });
558
+ },
559
+
560
+ postQuestion() {
561
+ this.rebuildFlag = true;
562
+ this.generateCount = 0;
563
+ this.aiResponse = {}
564
+ this.isGenerating = true;
565
+
566
+ // 初始化题型生成计数器
567
+ this.typeGeneratedCounts = {};
568
+ this.pendingGenerations = [];
569
+
506
570
  const selectedTypes = Object.keys(this.form.selectedTypes).filter(key => this.form.selectedTypes[key])
507
- const questionTypes = selectedTypes
508
- const difficultys = selectedTypes.map(type => this.form.typeDifficulties[type])
509
571
 
572
+ // 初始化每个题型的计数器和待生成队列
573
+ selectedTypes.forEach(type => {
574
+ this.typeGeneratedCounts[type] = 0;
575
+ const count = this.form.typeCounts[type] || 1;
576
+
577
+ // 将每个需要生成的题目加入队列
578
+ for (let i = 0; i < count; i++) {
579
+ this.pendingGenerations.push({
580
+ type: type,
581
+ difficulty: this.form.typeDifficulties[type],
582
+ index: i
583
+ });
584
+ }
585
+ });
586
+
587
+ // 开始生成题目
588
+ this.pendingGenerations.forEach(item => {
589
+ this.generateSingleQuestion(item.type, item.difficulty);
590
+ });
591
+ },
592
+
593
+ // 生成单个题目的方法
594
+ generateSingleQuestion(questionType, difficulty) {
510
595
  let obj = {
511
596
  modelType: 'aliyun',
512
597
  questionAddCmd: {
513
- questionTypes: questionTypes,
598
+ questionTypes: [questionType], // 指定单个题型
514
599
  count: 1,
515
600
  knowledge: this.form.knowledge.join(' '),
516
601
  knowledgeId: this.form.knowledgeId[this.form.knowledgeId.length - 1],
517
- difficultys: difficultys,
602
+ difficultys: [difficulty],
518
603
  prompt: this.form.prompt
519
604
  },
520
605
  sessionId: this.aiResponse.sessionId ? this.aiResponse.sessionId : '',
521
606
  businessSource: this.businessSource,
522
607
  courseId: this.courseId,
523
608
  }
524
-
609
+
525
610
  getAiQuestion(obj).then(res => {
526
611
  if (res.success) {
527
- this.loading && this.loading.close()
528
612
  if (res.data && res.data.questions && res.data.questions.length > 0) {
529
613
  const newQuestion = res.data.questions[0];
530
- const questionType = newQuestion.type;
614
+
531
615
  // 检查是否有重复的题目标题和题型
532
616
  const isDuplicate = this.checkDuplicateQuestion(newQuestion, questionType);
533
617
 
534
618
  if (isDuplicate) {
619
+ // 重复题目,重新生成
535
620
  const repetitionQuestions = this.getGeneratedQuestionsByType(questionType);
536
- this.regenerateWithRepetitionForReSend(obj, repetitionQuestions, questionType);
621
+ this.regenerateWithRepetition(obj, repetitionQuestions, questionType);
622
+ return;
623
+ }
624
+
625
+ // 验证返回的题目类型是否正确
626
+ if (newQuestion.type && newQuestion.type !== questionType) {
627
+ console.log(`期望题型: ${questionType}, 实际题型: ${newQuestion.type}, 重新生成`);
628
+ this.generateSingleQuestion(questionType, difficulty);
537
629
  return;
538
630
  }
539
631
 
@@ -545,10 +637,15 @@ export default {
545
637
  this.$set(newQuestion, 'evaluate', 0)
546
638
  // 设置题目类型,便于后续统计
547
639
  this.$set(newQuestion, 'type', questionType)
640
+
641
+ // 更新该题型的生成计数
642
+ this.typeGeneratedCounts[questionType]++;
643
+
548
644
  this.showGenerateResult();
549
645
  } else {
550
646
  this.$message.warning('题目获取失败,重新生成中...')
551
- return this.reSend()
647
+ // 重新生成指定题型
648
+ this.generateSingleQuestion(questionType, difficulty);
552
649
  }
553
650
  } else {
554
651
  this.isGenerating = false;
@@ -563,91 +660,6 @@ export default {
563
660
  })
564
661
  },
565
662
 
566
- //发送请求
567
- sendPost() {
568
- checkVersion(this.businessSource).then(res => {
569
- console.log(res);
570
- if (res.errCode === '403') {
571
- this.$message.warning(res.errMessage)
572
- } else {
573
- this.postQuestion();
574
- }
575
- });
576
- },
577
-
578
- postQuestion() {
579
- this.rebuildFlag = true;
580
- this.generateCount = 0;
581
- this.aiResponse = {}
582
- this.isGenerating = true;
583
-
584
- const selectedTypes = Object.keys(this.form.selectedTypes).filter(key => this.form.selectedTypes[key])
585
-
586
- // 按题型分别生成题目
587
- selectedTypes.forEach(type => {
588
- const count = this.form.typeCounts[type] || 1;
589
- const difficulty = this.form.typeDifficulties[type];
590
-
591
- // 为每种题型生成指定数量的题目
592
- for (let i = 0; i < count; i++) {
593
- let obj = {
594
- modelType: 'aliyun',
595
- questionAddCmd: {
596
- questionTypes: [type], // 单个题型
597
- count: 1,
598
- knowledge: this.form.knowledge.join(' '),
599
- knowledgeId: this.form.knowledgeId[this.form.knowledgeId.length - 1],
600
- difficultys: [difficulty], // 对应的难度
601
- prompt: this.form.prompt
602
- },
603
- sessionId: this.aiResponse.sessionId ? this.aiResponse.sessionId : '',
604
- businessSource: this.businessSource,
605
- courseId: this.courseId,
606
- }
607
-
608
- getAiQuestion(obj).then(res => {
609
- if (res.success) {
610
- if (res.data && res.data.questions && res.data.questions.length > 0) {
611
- const newQuestion = res.data.questions[0];
612
-
613
- // 检查是否有重复的题目标题和题型
614
- const isDuplicate = this.checkDuplicateQuestion(newQuestion, type);
615
-
616
- if (isDuplicate) {
617
- // 只传递当前题型
618
- const repetitionQuestions = this.getGeneratedQuestionsByType(type);
619
- this.regenerateWithRepetition(obj, repetitionQuestions, type);
620
- return;
621
- }
622
-
623
- if (this.aiResponse.questions && this.aiResponse.questions.length > 0) {
624
- this.aiResponse.questions.push(newQuestion);
625
- } else {
626
- this.aiResponse = res.data;
627
- }
628
- this.$set(newQuestion, 'evaluate', 0)
629
- // 设置题目类型,便于后续统计
630
- this.$set(newQuestion, 'type', type)
631
- this.showGenerateResult();
632
- } else {
633
- this.$message.warning('题目获取失败,重新生成中...')
634
- return this.reSend()
635
- }
636
- } else {
637
- this.isGenerating = false;
638
- this.$message.warning('题目获取失败')
639
- this.rebuildFlag = false;
640
- }
641
- }).catch(error => {
642
- console.log("error:" + error);
643
- this.isGenerating = false;
644
- this.$message.warning('题目获取失败')
645
- this.rebuildFlag = false;
646
- })
647
- }
648
- });
649
- },
650
-
651
663
  //获取知识点名称
652
664
  getKnowledgeName(e, array) {
653
665
  array.forEach(item => {
@@ -839,6 +851,13 @@ export default {
839
851
  this.$set(newQuestion, 'evaluate', 0)
840
852
  // 设置题目类型,便于后续统计
841
853
  this.$set(newQuestion, 'type', questionType)
854
+
855
+ // 更新该题型的生成计数
856
+ if (!this.typeGeneratedCounts[questionType]) {
857
+ this.typeGeneratedCounts[questionType] = 0;
858
+ }
859
+ this.typeGeneratedCounts[questionType]++;
860
+
842
861
  this.showGenerateResult();
843
862
  } else {
844
863
  this.$message.warning('重新生成题目失败')