← Lesson
Refuse When Nothing Matches
Joeven
Run
Reset
Python loads on first run
CHUNKS = [ {"id": "chunk-01", "text": "Refunds take 5-7 business days. Never cash."}, ] def score(query, text): return len(set(query.lower().split()) & set(text.lower().split())) def answer(query, tau=1): best = max(CHUNKS, key=lambda c: score(query, c["text"])) s = score(query, best["text"]) if s < tau: return {"answer": "cannot: not in handbook", "refused": True, "score": s} return { "answer": best["text"], "citations": [best["id"]], "refused": False, "score": s, } print(answer("refunds days")) print(answer("equine dental"))
Run to execute this in your browser. Nothing is sent to a server.