← Lesson
Citations
Joeven
Run
Reset
Python loads on first run
def check_cite(answer, allowed_ids, sources): used = [i for i in allowed_ids if i in answer] if not used: return "no citation" blob = " ".join(sources.get(i, "") for i in used) for token in answer.replace("(", " ").replace(")", " ").split(): if token.startswith("job-") and token not in blob and token not in used: return "id not in sources: " + token return "ok:" + ",".join(used) allowed = ["tool_get_job", "doc_policy"] sources = { "tool_get_job": "job-17 status=failed", "doc_policy": "Refunds take 5-7 days", } print(check_cite("failed (tool_get_job) on job-17", allowed, sources)) print(check_cite("failed on job-99", allowed, sources)) print(check_cite("all good", allowed, sources))
Run to execute this in your browser. Nothing is sent to a server.