Download mpbench/prompts.py from Manprot/MPBench0-1126: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/datasets/Manprot/MPBench0-1126/resolve/main/mpbench/prompts.py
- Command line
-
hf download hf://datasets/Manprot/MPBench0-1126/mpbench/prompts.py
-
curl -L -o prompts.py https://huggingface.co/datasets/Manprot/MPBench0-1126/resolve/main/mpbench/prompts.py
1.75 kB
| """The two prompt formats. A chat model gets its own template, a base model gets question-answer shots.""" | |
| import json | |
| import re | |
| SHOTS = ("Question: What sound does a cow make?\nAnswer: Moo.\n\n" | |
| "Question: What is 1 + 1?\nAnswer: 2\n\n" | |
| "Question: What do birds use to fly?\nAnswer: Wings.\n\n") | |
| LIMIT = {"chat_qa": 80, "html": 384, "math": 96, "world_basic": 40, "world_advanced": 40, "tool_calls": 80} | |
| def tool_text(task): | |
| tools = "\n".join(json.dumps(t, ensure_ascii=False) for t in task["tools"]) | |
| return (f"Tools:\n{tools}\n\nAnswer with one JSON tool call that uses one of the tools.\n\n" | |
| "Example request: Flip a coin three times.\n" | |
| 'Tool call: {"name": "flip_coin", "arguments": {"times": 3}}\n\n' | |
| f"Request: {task['question']}") | |
| def user_message(task): | |
| return tool_text(task) if task["section"] == "tool_calls" else task["question"] | |
| def base_prompt(task): | |
| if task["section"] == "html": | |
| return f"Question: {task['question']}\nAnswer:\n```html\n" | |
| if task["section"] == "tool_calls": | |
| return f"{tool_text(task)}\nTool call:" | |
| return f"{SHOTS}Question: {task['question']}\nAnswer:" | |
| def base_stop(section): | |
| if section == "html": | |
| return r"```" | |
| if section == "tool_calls": | |
| return r"\n\s*(?:Request|Tools)\s*:|(?<=\})\s*\n" | |
| if section == "chat_qa": | |
| return r"(?i)\bquestion\s*:" | |
| return r"(?i)\bquestion\s*:|(?<=\S)[ \t]*\n" # short answers end with their line | |
| def trim(text, section, fmt): | |
| """Cut what a base model writes after its answer.""" | |
| if fmt == "chat": | |
| return text.strip() | |
| m = re.search(base_stop(section), text) | |
| return (text[:m.start()] if m else text).strip() | |