From dd213df0e292677121914572742f519ad4455cdd Mon Sep 17 00:00:00 2001 From: lacerate551 <128470311+lacerate551@users.noreply.github.com> Date: Mon, 22 Jun 2026 19:06:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(exam=5Fpkg):=20v2=E8=A1=A5=E9=A2=98?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E4=B8=8Efinal=E5=B7=B2=E6=9C=89=E9=A2=98?= =?UTF-8?q?=E5=B9=B2=E4=BA=A4=E5=8F=89=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补题阶段仅和exclude_stems去重,未检查final中已有题干, 可能补出重复题目。修复:收集final题干+exclude_stems合并传入 _deduplicate_questions,多题型补题时逐轮累积排除列表。 --- exam_pkg/generator.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/exam_pkg/generator.py b/exam_pkg/generator.py index 1bfceda..332861f 100644 --- a/exam_pkg/generator.py +++ b/exam_pkg/generator.py @@ -1300,12 +1300,21 @@ def generate_questions_structured_v2( if shortage_types: logger.info(f" [v2] 补题: 缺少题型 {dict(shortage_types)}") + # 收集 final 中已有题干,补题时一并排除 + existing_stems = [q.get('content', {}).get('stem', '') for q in final if q.get('content', {}).get('stem')] + combined_exclude = list(exclude_stems or []) + existing_stems + for q_type, shortage in shortage_types.items(): logger.info(f" 补充 {q_type} {shortage} 道...") extra = generator._makeup_questions(chunks, q_type, shortage, difficulty, document_name) - # 补题也需去重 - extra_deduped = _deduplicate_questions(extra, exclude_stems=exclude_stems) + # 补题需与已有题目 + 跨调用排除列表一起去重 + extra_deduped = _deduplicate_questions(extra, exclude_stems=combined_exclude) final.extend(extra_deduped[:shortage]) + # 将新补的题干也加入排除列表,防止后续题型补出重复 + for q in extra_deduped: + stem = q.get('content', {}).get('stem', '') + if stem: + combined_exclude.append(stem) # 补题后重新统计 type_counts = defaultdict(int)