← Lesson
Few-Shot Prompting
Joeven
Run
Reset
Python loads on first run
EXAMPLES = [ ("refund the invoice from March", "billing"), ("my card was charged twice", "billing"), ("reset the password on my account", "account"), ("I cannot log in after 2FA", "account"), ("the runner crashed with OOM", "infra"), ("agent loop hit max_steps again", "infra"), ] def tokenize(text): return {w for w in text.lower().replace("?", " ").split() if len(w) > 2} def classify(text, examples): q = tokenize(text) best_label, best = "unknown", 0.0 for ex, label in examples: overlap = len(q & tokenize(ex)) score = overlap / max(len(q), 1) if score > best: best_label, best = label, score return best_label, round(best, 3) queries = [ "please refund last month invoice", "password reset link is dead", "OOM killed the runner", "what is the meaning of life", ] print("zero-shot with no examples would be: unknown") for q in queries: label, score = classify(q, EXAMPLES) print(repr(q), "->", label, "score", score) print("no infra shots?", classify("OOM killed the runner", EXAMPLES[:4]))
Run to execute this in your browser. Nothing is sent to a server.