mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 11:19:51 +08:00
Merge pull request #2000 from drakeo338/claude/1993-fix
fix(mastery): show the picked option's text next to its letter in the grade seed
This commit is contained in:
@@ -574,11 +574,11 @@ class MasteryLoopCapability:
|
||||
{**result, "is_correct": result.get("is_correct", grade.get("is_correct"))}
|
||||
)
|
||||
learner_answer = str(result.get("learner_answer") or "").strip()
|
||||
learner_body = str(result.get("learner_body") or "").strip()
|
||||
picked = f"{learner_answer}: {learner_body}" if learner_body else learner_answer
|
||||
lines = [
|
||||
"[Mastery] The learner answered the open question on its card and the "
|
||||
f"engine reports: {outcome}"
|
||||
+ (f' (they answered "{learner_answer}")' if learner_answer else "")
|
||||
+ ".",
|
||||
f"engine reports: {outcome}" + (f' (they answered "{picked}")' if picked else "") + ".",
|
||||
str(result.get("feedback") or ""),
|
||||
]
|
||||
if result.get("final") is False or outcome == "ungraded":
|
||||
|
||||
@@ -112,6 +112,7 @@ def build_grade_result(
|
||||
it is graded — which is exactly when they are worth reading.
|
||||
"""
|
||||
label = str(correct_label or "").strip()
|
||||
picked = str(learner_answer or "").strip()
|
||||
payload = {
|
||||
"question_id": str(question_id or ""),
|
||||
"is_correct": is_correct,
|
||||
@@ -120,6 +121,10 @@ def build_grade_result(
|
||||
"feedback": feedback,
|
||||
"confidence": confidence,
|
||||
"learner_answer": str(learner_answer or ""),
|
||||
# The option text behind the picked letter: the card may show the
|
||||
# options in a different order than the tutor registered them, so the
|
||||
# letter alone does not say what the learner chose.
|
||||
"learner_body": str(choice_options.get(picked) or "") if picked else "",
|
||||
"correct_label": label,
|
||||
"correct_body": str(choice_options.get(label) or "") if label else "",
|
||||
"explanation": str(explanation or ""),
|
||||
|
||||
@@ -804,3 +804,35 @@ def test_kb_seed_is_left_alone_outside_mastery_mode() -> None:
|
||||
metadata={"mastery_card_answered": True},
|
||||
)
|
||||
assert MasteryLoopCapability().skip_kb_seed(context) is False
|
||||
|
||||
|
||||
def test_seed_names_the_option_the_learner_picked_not_just_its_letter():
|
||||
"""A bare letter is ambiguous once the card shuffles the options.
|
||||
|
||||
The tutor registered the options in its own order; the card shows (and the
|
||||
engine persists) a shuffled one. "D" therefore means a different option in
|
||||
the tutor's context than on the learner's screen (HKUDS/DeepTutor#1993),
|
||||
so the picked option's body has to travel with the letter.
|
||||
"""
|
||||
from deeptutor.learning.question_card import build_grade_result
|
||||
|
||||
shuffled = {
|
||||
"A": "Each instance remembers request ids in local memory",
|
||||
"B": "Disable the send button while waiting",
|
||||
"C": "SELECT first, then INSERT",
|
||||
"D": "Idempotency key plus an atomic claim in the backend",
|
||||
}
|
||||
result = build_grade_result(
|
||||
question_id="q-1",
|
||||
is_correct=True,
|
||||
learner_answer="D",
|
||||
correct_label="D",
|
||||
choice_options=shuffled,
|
||||
explanation="why",
|
||||
)
|
||||
context = _context()
|
||||
context.metadata["mastery_card_grade"] = {"is_correct": True, "result": result}
|
||||
|
||||
seed = MasteryLoopCapability()._grade_seed(context)
|
||||
|
||||
assert "Idempotency key plus an atomic claim in the backend" in seed
|
||||
|
||||
Reference in New Issue
Block a user