← Lesson
Ground the Critic
Joeven
Run
Reset
Python loads on first run
SNIPS = { "s1": "Paris rain 12C", "s2": "Museum closed Mondays", } def critic(answer, cited, snips, must_cite): errors = [] for sid in cited: if sid not in snips: errors.append("unknown cite " + sid) for sid in must_cite: if sid not in cited: errors.append("missing " + sid) elif snips[sid].split()[0].lower() not in answer.lower(): errors.append("answer ignores " + sid) if errors: return {"ok": False, "errors": errors} return {"ok": True, "errors": []} print(critic("Paris rain 12C. Museum closed Mondays.", ["s1", "s2"], SNIPS, ["s1", "s2"])) print(critic("Bring shorts, it is hot.", ["s1"], SNIPS, ["s1"])) print(critic("Paris rain 12C.", ["s9"], SNIPS, ["s1"]))
Run to execute this in your browser. Nothing is sent to a server.