From ac41ca89a7b6c5cd381712dcd9706e066d4411a4 Mon Sep 17 00:00:00 2001 From: magisk317 Date: Mon, 13 Oct 2025 15:30:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20question=5Fmaker=20?= =?UTF-8?q?=E4=B8=AD=20UnboundLocalError=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 get_random_unanswered_conflict() 方法中新增 else 分支 - 当所有冲突 raise_time >= 1 时,按 5% 概率随机选择 - 避免 chosen_conflict 未赋值导致的 UnboundLocalError 异常 --- src/memory_system/question_maker.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/memory_system/question_maker.py b/src/memory_system/question_maker.py index 316afee5..cc6c35c0 100644 --- a/src/memory_system/question_maker.py +++ b/src/memory_system/question_maker.py @@ -70,11 +70,15 @@ class QuestionMaker: # 按权重随机选择 chosen_conflict = random.choices(conflicts, weights=weights, k=1)[0] + else: + # 所有冲突都已被提问过(raise_time ≥ 1),仅 5% 概率返回 + if random.random() > 0.05: + return None + chosen_conflict = random.choice(conflicts) # 选中后,自增 raise_time 并保存 - chosen_conflict.raise_time = (getattr(chosen_conflict, "raise_time", 0) or 0) + 1 - chosen_conflict.save() - + chosen_conflict.raise_time = (getattr(chosen_conflict, "raise_time", 0) or 0) + 1 + chosen_conflict.save() return chosen_conflict