"""The fixed prompt set: 4 categories x 3 prompts, all written for this benchmark. Category keys: code, extract, explain, creative. """ from pathlib import Path HERE = Path(__file__).parent CODE = (HERE / "prompts" / "inventory.py").read_text() PARAGRAPH = ( "On 3 March our team moved the build server from the old office in Pune to a rented rack " "in a Mumbai data centre. The move took 2 days instead of the planned 1 because the rack " "arrived without rails. Ravi Menon handled the network cut-over and Anita Rao updated the " "DNS records. The monthly cost went from 18,000 rupees for office power and cooling to " "26,500 rupees for the rack, but build times dropped from 14 minutes to 9 minutes on " "average because the new uplink is 10 Gbit/s instead of 1 Gbit/s. Two follow-ups remain " "open: setting up off-site backups (owner: Anita, due 20 March) and retiring the old UPS " "(owner: Ravi, no date yet)." ) PROMPTS = [ # (a) code completion / refactor of our own small Python file ("code", "code_refactor", "Refactor this Python class to use context managers for file handling, dataclasses for " "items, and type hints. Keep the same public methods. Reply with only the code.\n\n```python\n" + CODE + "```"), ("code", "code_tests", "Write pytest unit tests for the add, remove and low_stock methods of this class. Use the " "tmp_path fixture where a file is needed. Reply with only the code.\n\n```python\n" + CODE + "```"), ("code", "code_method", "Add a method `restock_report(self, threshold, target)` to this class that returns a list of " "(sku, name, units_to_order) tuples for every item below the threshold, ordering enough to " "reach the target quantity, sorted by sku. Reply with the full updated class only.\n\n```python\n" + CODE + "```"), # (b) structured extraction / rewrite of a paragraph we wrote ("extract", "extract_json", "Extract the facts from this paragraph into JSON with keys: date, from_location, " "to_location, planned_days, actual_days, delay_reason, people (list of {name, task}), " "cost_before_inr, cost_after_inr, build_minutes_before, build_minutes_after, " "follow_ups (list of {task, owner, due}). Reply with only the JSON.\n\n" + PARAGRAPH), ("extract", "extract_table", "Rewrite this paragraph as a Markdown table with columns: Item, Before, After, Notes. " "Include one row each for location, cost, build time, uplink speed and duration of the move. " "Then list the open follow-ups as Markdown checkboxes.\n\n" + PARAGRAPH), ("extract", "extract_bullets", "Rewrite this paragraph as a short status update for a team chat: a one-line summary, then " "bullet points for what changed, the numbers, and who owns what next. Keep every number " "exactly as written.\n\n" + PARAGRAPH), # (c) factual explanation ("explain", "explain_tcp", "Explain how TCP slow start works: what the congestion window is, how it grows, what " "ssthresh does, and what happens on packet loss. Aim for a reader who knows basic networking."), ("explain", "explain_btree", "Explain how a B-tree index speeds up lookups in a relational database, including why " "databases prefer B-trees over binary search trees on disk, and what happens on an insert " "that fills a node."), ("explain", "explain_dns", "Explain step by step what happens when a browser resolves the domain name www.example.com " "for the first time, from the stub resolver to the authoritative server, including caching " "and TTLs."), # (d) open-ended creative writing ("creative", "creative_story", "Write the opening of a short story about a lighthouse keeper who finds a radio that " "receives messages from the next morning. Literary tone, no title."), ("creative", "creative_poem", "Write a free-verse poem about the monsoon arriving in a crowded city, told from the point " "of view of a street dog."), ("creative", "creative_letter", "Write a letter from a retired train driver to the last steam locomotive they drove, which " "is now in a museum. Warm, specific, a little funny."), ] WARMUP = ("warmup", "warmup", "Describe, in a few paragraphs, how a bicycle gear system works and why cyclists shift gears.") CATEGORIES = ["code", "extract", "explain", "creative"] def chat_ids(tokenizer, text): """Chat-templated prompt token ids with thinking disabled (Qwen3.x `enable_thinking=False`).""" msgs = [{"role": "user", "content": text}] out = tokenizer.apply_chat_template(msgs, add_generation_prompt=True, enable_thinking=False, tokenize=True) if isinstance(out, dict) or hasattr(out, "input_ids"): out = out["input_ids"] return list(out)