prompts.py 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """Prompt pools shared by the decode benchmarks. prompt_for(work, i) gives the i-th prompt of a
  2. workload; "mixed" rotates code, prose and structured."""
  3. PROMPTS = {
  4. "code": [f"Write {t} in Python. Code only." for t in (
  5. "a red-black tree with insert, delete and rebalancing", "an LRU cache with O(1) get and put",
  6. "a trie with insert, search and prefix listing", "a binary min-heap with push, pop and heapify",
  7. "a JSON tokenizer that yields typed tokens", "a fixed-size thread pool with a work queue",
  8. "Dijkstra's shortest path over an adjacency list", "a dense matrix class with multiply and transpose")],
  9. "prose": [f"Explain {t}, in flowing prose. No code, no lists." for t in (
  10. "how a hash map works", "how TCP opens and closes a connection", "how photosynthesis stores energy",
  11. "how a tracing garbage collector works", "how compound interest grows savings", "how vaccines train immunity",
  12. "how plate tectonics shapes continents", "how a compiler turns source into machine code")],
  13. "structured": [f"{t} No commentary." for t in (
  14. "Count from 1 to 200, comma separated.", "List the integers from 300 to 480, comma separated.",
  15. "List the multiples of 3 from 3 to 540, comma separated.", "Count down from 220 to 1, comma separated.",
  16. "List the even numbers from 2 to 380, comma separated.", "List the squares of 1 to 90, comma separated.",
  17. "List the integers from 1000 to 1150, comma separated.", "List the multiples of 7 from 7 to 1050, comma separated.")],
  18. }
  19. SUFFIX = ["", " Be thorough."]
  20. # Streams past the first 16 draw from these, so large batches do not repeat
  21. # prompts (repeated greedy prompts route to the same experts).
  22. EXTRA = {
  23. "code": [f"Write {t} in Python. Code only." for t in (
  24. "a union-find with path compression", "a bloom filter with k hash functions", "an interval tree with overlap queries",
  25. "a skip list with insert and search", "a ring buffer with overwrite", "a token bucket rate limiter",
  26. "a consistent hash ring", "an A* path finder on a grid", "a topological sort with cycle detection",
  27. "a CSV parser that handles quoted fields", "a Huffman encoder and decoder", "a sudoku solver with backtracking",
  28. "a B-tree of order 4 with insert", "a Fenwick tree with range sums", "a segment tree with lazy propagation",
  29. "an event loop with timers", "a regex matcher for . * and ?", "a markdown to HTML converter for headings and lists",
  30. "a merge sort and a quicksort with benchmarks", "a k-means clustering routine", "a simple stack-based VM",
  31. "a URL router with path parameters", "an INI file parser", "a priority task scheduler",
  32. "a diff of two lists by longest common subsequence", "a base64 encoder and decoder", "a sparse matrix in CSR form",
  33. "a minimal HTTP request parser", "a finite state machine for a vending machine", "a memoizing decorator with TTL")],
  34. "prose": [f"Explain {t}, in flowing prose. No code, no lists." for t in (
  35. "how a refrigerator moves heat", "how the heart pumps blood", "how a jet engine makes thrust",
  36. "how DNS resolves a name", "how a bill becomes law", "how bread rises", "how glaciers carve valleys",
  37. "how a transistor switches", "how the stock market sets prices", "how bees communicate",
  38. "how GPS finds a position", "how a lock and key work", "how clouds form rain", "how a piano makes sound",
  39. "how the moon causes tides", "how antibiotics kill bacteria", "how a camera sensor records light",
  40. "how inflation erodes money", "how a river delta forms", "how public key encryption works",
  41. "how muscles contract", "how a wind turbine makes power", "how the immune system spots a virus",
  42. "how a library catalogs books", "how coffee is roasted", "how an elevator stays safe",
  43. "how sleep restores the brain", "how a sailboat moves upwind", "how volcanoes erupt", "how a database index speeds queries")],
  44. "structured": [f"List the multiples of {m} from {m * a} to {m * (a + 150)}, comma separated. No commentary."
  45. for m in (2, 3, 4, 5, 6, 7, 8, 9, 11, 13) for a in (10, 400, 900)],
  46. }
  47. STYLE = ["", " Keep it short.", " Be thorough.", " Aim it at a beginner.", " Aim it at an expert.",
  48. " Use plain words.", " Be precise.", " Be complete."]
  49. def prompt_for(work, i):
  50. if work == "mixed":
  51. return prompt_for(("code", "prose", "structured")[i % 3], i // 3)
  52. if i < 16:
  53. ps = PROMPTS[work]
  54. return ps[i % len(ps)] + SUFFIX[(i // len(ps)) % len(SUFFIX)]
  55. ex = EXTRA[work]
  56. j = i - 16
  57. return ex[j % len(ex)] + STYLE[(j // len(ex)) % len(STYLE)]