Datasets:
Download tooluse1/cases_build.py from HardcoreAI/ToolUse.1: direct link, hf CLI and curl.
- Browser
- Download file 21 kB
-
https://huggingface.co/datasets/HardcoreAI/ToolUse.1/resolve/main/tooluse1/cases_build.py
- Command line
-
hf download hf://datasets/HardcoreAI/ToolUse.1/tooluse1/cases_build.py
-
curl -L -o cases_build.py https://huggingface.co/datasets/HardcoreAI/ToolUse.1/resolve/main/tooluse1/cases_build.py
21 kB
| """Frozen corpus of ToolUse.1 (English only). | |
| Cases are authored declaratively here and expanded into the published JSONL by | |
| `build()`. Ids are stable and human-readable: `<category>-en-<index>`, so a | |
| result table can be read without a lookup. | |
| Design rules for authoring new cases: | |
| * every call case declares the *canonical* arguments, not a string the model | |
| is expected to echo; argument comparison is semantic (see `tools.py`); | |
| * every no-call case either constrains the free-text answer (`answer_contains_*`) | |
| or deliberately leaves it open when any reasonable answer is acceptable; | |
| * cases that punish a spurious call are concentrated in `negative` and | |
| `clarification`, and are weighted equally with call cases in the score. | |
| """ | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from typing import Any, Sequence | |
| from .schema import Case, ExpectCall, ExpectNoCall, Expectation, Message | |
| ALL_TOOLS: tuple[str, ...] = ( | |
| "calculator", | |
| "get_weather", | |
| "web_search", | |
| "translate", | |
| "convert_currency", | |
| "convert_units", | |
| "set_timer", | |
| "save_note", | |
| "get_time", | |
| ) | |
| _SHORT_TOOLS: tuple[str, ...] = ("calculator", "get_weather", "get_time", "set_timer") | |
| _LANG_TOOLS: tuple[str, ...] = ("translate", "save_note", "get_time", "web_search") | |
| def call(name: str, **args: Any) -> ExpectCall: | |
| return ExpectCall(name=name, args=args) | |
| def none(any_: Sequence[Sequence[str]] = (), all_: Sequence[str] = ()) -> ExpectNoCall: | |
| return ExpectNoCall(answer_contains_any=tuple(tuple(group) for group in any_), answer_contains_all=tuple(all_)) | |
| def _case( | |
| cid: str, | |
| category: str, | |
| user: str, | |
| expect: Expectation, | |
| tools: Sequence[str] = ALL_TOOLS, | |
| difficulty: str = "easy", | |
| history: Sequence[Message] = (), | |
| notes: str = "", | |
| ) -> Case: | |
| return Case( | |
| id=cid, | |
| lang="en", | |
| category=category, | |
| difficulty=difficulty, | |
| tools=tuple(tools), | |
| user=user, | |
| expect=expect, | |
| history=tuple(history), | |
| notes=notes, | |
| ) | |
| def _tool_turn(name: str, args: dict[str, Any], result: str) -> tuple[Message, Message]: | |
| return ( | |
| Message(role="assistant", content="", tool_name=name, tool_args=args), | |
| Message(role="tool", content=result, tool_name=name), | |
| ) | |
| def _cases() -> list[Case]: | |
| cases: list[Case] = [] | |
| # ---------------------------------------------------------------- calculator | |
| calculator_en = [ | |
| ("What is 45 plus 12?", dict(expression="45 + 12")), | |
| ("Calculate 128 * 7 for me.", dict(expression="128 * 7")), | |
| ("What's 15% of 240?", dict(expression="0.15 * 240")), | |
| ("Compute (18 + 24) / 6.", dict(expression="(18 + 24) / 6")), | |
| ("How much is 2 to the power of 10?", dict(expression="2 ** 10")), | |
| ("What is the square root of 144?", dict(expression="sqrt(144)")), | |
| ("Add 0.1 and 0.2.", dict(expression="0.1 + 0.2")), | |
| ("What's 17 times 3 minus 5?", dict(expression="17 * 3 - 5")), | |
| ("A shirt costs 849 and I want three of them. What's the total?", dict(expression="849 * 3"), "medium"), | |
| ("What's 1000 divided by 8, then squared?", dict(expression="(1000 / 8) ** 2"), "medium"), | |
| ("Round 187.456 to the nearest integer.", dict(expression="round(187.456)"), "medium"), | |
| ("What's the remainder when 155 is divided by 7?", dict(expression="155 % 7"), "medium"), | |
| ("How much is 3.5 raised to the power of 4?", dict(expression="3.5 ** 4"), "hard"), | |
| ("What is log10 of 1000?", dict(expression="log10(1000)"), "hard"), | |
| ("What's the average of 14, 27 and 40?", dict(expression="(14 + 27 + 40) / 3"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(calculator_en, 1): | |
| cases.append( | |
| _case(f"calc-en-{index:03d}", "calculator", user, call("calculator", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # ------------------------------------------------------------------ weather | |
| weather_en = [ | |
| ("What's the weather in Berlin?", dict(city="Berlin")), | |
| ("Is it raining in Tokyo right now?", dict(city="Tokyo")), | |
| ("Tell me the current temperature in Moscow.", dict(city="Moscow")), | |
| ("What's the weather like in New York today?", dict(city="New York")), | |
| ("What's the weather in St. Petersburg?", dict(city="Saint Petersburg")), | |
| ("What's the weather in Chicago in Fahrenheit?", dict(city="Chicago", unit="fahrenheit")), | |
| ("Current temperature in Dubai in Celsius?", dict(city="Dubai", unit="celsius"), "medium"), | |
| ("Do I need an umbrella in London this afternoon?", dict(city="London"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(weather_en, 1): | |
| cases.append( | |
| _case(f"weather-en-{index:03d}", "get_weather", user, call("get_weather", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # --------------------------------------------------------------- web_search | |
| search_en = [ | |
| ("Search the web for the latest stable version of Rust.", dict(query="latest stable Rust version")), | |
| ("Look up who the CEO of NVIDIA is.", dict(query="CEO of NVIDIA")), | |
| ("Find the current price of an RTX 4050 laptop.", dict(query="RTX 4050 laptop price")), | |
| ("Search for reviews of the Framework 13 laptop.", dict(query="Framework 13 laptop review")), | |
| ("Look up the population of Almaty.", dict(query="population of Almaty")), | |
| ("Find out when the next Formula 1 race is.", dict(query="next Formula 1 race")), | |
| ("Search the web for Python 3.13 release notes.", dict(query="Python 3.13 release notes"), "medium"), | |
| ("Look up whether the Nova-1.1-0.8B model card mentions GGUF.", dict(query="Nova-1.1-0.8B GGUF"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(search_en, 1): | |
| cases.append( | |
| _case(f"search-en-{index:03d}", "web_search", user, call("web_search", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # ----------------------------------------------------------------- translate | |
| translate_en = [ | |
| ("Translate 'good morning' to French.", dict(text="good morning", target_language="fr")), | |
| ("Translate 'thank you' into Spanish.", dict(text="thank you", target_language="es")), | |
| ("How do you say 'how are you' in German?", dict(text="how are you", target_language="de")), | |
| ("Translate 'I would like a coffee' to Italian.", dict(text="I would like a coffee", target_language="it")), | |
| ("Translate 'hello' to Japanese.", dict(text="hello", target_language="ja")), | |
| ("Translate 'where is the station' into Russian.", dict(text="where is the station", target_language="ru")), | |
| ("Translate 'the book is on the table' into Portuguese.", dict(text="the book is on the table", target_language="pt"), "medium"), | |
| ("Translate 'see you tomorrow' to Turkish.", dict(text="see you tomorrow", target_language="tr"), "medium"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(translate_en, 1): | |
| cases.append( | |
| _case(f"translate-en-{index:03d}", "translate", user, call("translate", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # ----------------------------------------------------------- convert_currency | |
| currency_en = [ | |
| ("Convert 100 USD to EUR.", dict(amount=100, from_currency="USD", to_currency="EUR")), | |
| ("How many rubles is 500 dollars?", dict(amount=500, from_currency="USD", to_currency="RUB")), | |
| ("Convert 250 euros to pounds.", dict(amount=250, from_currency="EUR", to_currency="GBP")), | |
| ("What's 1000 rubles in tenge?", dict(amount=1000, from_currency="RUB", to_currency="KZT")), | |
| ("Convert 75 GBP to JPY.", dict(amount=75, from_currency="GBP", to_currency="JPY"), "medium"), | |
| ("How much is 50 EUR in USD?", dict(amount=50, from_currency="EUR", to_currency="USD")), | |
| ("Convert 30 Canadian dollars to US dollars.", dict(amount=30, from_currency="CAD", to_currency="USD"), "medium"), | |
| ("Exchange 20000 tenge for rubles.", dict(amount=20000, from_currency="KZT", to_currency="RUB"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(currency_en, 1): | |
| cases.append( | |
| _case( | |
| f"currency-en-{index:03d}", "convert_currency", user, | |
| call("convert_currency", **args), difficulty=rest[0] if rest else "easy", | |
| ) | |
| ) | |
| # -------------------------------------------------------------- convert_units | |
| units_en = [ | |
| ("Convert 5 km to miles.", dict(value=5, from_unit="km", to_unit="mi")), | |
| ("How many pounds is 70 kg?", dict(value=70, from_unit="kg", to_unit="lb")), | |
| ("Convert 180 cm to feet.", dict(value=180, from_unit="cm", to_unit="ft")), | |
| ("Convert 100 Fahrenheit to Celsius.", dict(value=100, from_unit="fahrenheit", to_unit="celsius")), | |
| ("How many kilometers is 26.2 miles?", dict(value=26.2, from_unit="mi", to_unit="km"), "medium"), | |
| ("Convert 2 liters to gallons.", dict(value=2, from_unit="l", to_unit="gal"), "medium"), | |
| ("Convert 500 milliliters to liters.", dict(value=500, from_unit="ml", to_unit="l"), "medium"), | |
| ("Convert 90 minutes to hours.", dict(value=90, from_unit="min", to_unit="h"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(units_en, 1): | |
| cases.append( | |
| _case( | |
| f"units-en-{index:03d}", "convert_units", user, | |
| call("convert_units", **args), difficulty=rest[0] if rest else "easy", | |
| ) | |
| ) | |
| # ------------------------------------------------------------------ timers | |
| timer_en = [ | |
| ("Set a 5 minute timer.", dict(seconds=300)), | |
| ("Remind me in 10 minutes.", dict(seconds=600)), | |
| ("Set a timer for 90 seconds.", dict(seconds=90)), | |
| ("Start a one hour timer.", dict(seconds=3600)), | |
| ("Put a 25 minute pomodoro timer on.", dict(seconds=1500), "medium"), | |
| ("Set a timer for two and a half minutes.", dict(seconds=150), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(timer_en, 1): | |
| cases.append( | |
| _case(f"timer-en-{index:03d}", "set_timer", user, call("set_timer", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # ------------------------------------------------------------------- notes | |
| note_en = [ | |
| ("Save a note titled 'Meeting' with the text 'Tuesday at 3 PM'.", dict(title="Meeting", content="Tuesday at 3 PM")), | |
| ("Add a note called 'Groceries' that says buy milk.", dict(title="Groceries", content="buy milk")), | |
| ("Save a note titled 'Ideas' with content 'build a benchmark'.", dict(title="Ideas", content="build a benchmark")), | |
| ("Save a note titled 'Server' with the text 'backup at 02:00'.", dict(title="Server", content="backup at 02:00")), | |
| ("Create a note called 'Quote' with the text 'stay hungry'.", dict(title="Quote", content="stay hungry"), "medium"), | |
| ("Save a reminder note titled 'Tickets' with content 'buy concert tickets'.", dict(title="Tickets", content="buy concert tickets"), "hard"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(note_en, 1): | |
| cases.append( | |
| _case(f"note-en-{index:03d}", "save_note", user, call("save_note", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # -------------------------------------------------------------------- time | |
| time_en = [ | |
| ("What time is it in Tokyo?", dict(timezone="Asia/Tokyo")), | |
| ("What's the current time in New York?", dict(timezone="America/New_York")), | |
| ("What time is it in London right now?", dict(timezone="Europe/London")), | |
| ("What time is it in Moscow?", dict(timezone="Europe/Moscow")), | |
| ("What time is it in Berlin?", dict(timezone="Europe/Berlin")), | |
| ("What's the date and time in Sydney?", dict(timezone="Australia/Sydney"), "medium"), | |
| ] | |
| for index, (user, args, *rest) in enumerate(time_en, 1): | |
| cases.append( | |
| _case(f"time-en-{index:03d}", "get_time", user, call("get_time", **args), difficulty=rest[0] if rest else "easy") | |
| ) | |
| # --------------------------------------------------------------- negatives | |
| negatives_en = [ | |
| ("What is the capital of Australia?", none(all_=["canberra"])), | |
| ("Who wrote 'War and Peace'?", none(any_=[["tolstoy", "leo tolstoy"]])), | |
| ("Explain what a hash function is.", none(all_=["hash"])), | |
| ("What's the difference between TCP and UDP?", none(all_=["tcp", "udp"])), | |
| ("Tell me a joke.", none()), | |
| ("What's your name?", none()), | |
| ("What is machine learning?", none(all_=["learning"])), | |
| ("Write a short poem about the sea.", none()), | |
| ("Is Python or Rust a better choice for CLI tools?", none()), | |
| ("What does HTTP 404 mean?", none(any_=[["not found", "not be found"]])), | |
| ("Can you explain recursion?", none(all_=["recursion"])), | |
| ("Give me three tips for better sleep.", none(all_=["sleep"])), | |
| ("Who painted the Mona Lisa?", none(any_=[["leonardo", "da vinci", "vinci"]])), | |
| ("What's the boiling point of water at sea level?", none(all_=["100"])), | |
| ("Summarize what an API is in one sentence.", none(all_=["api"])), | |
| ("In what year did the Berlin Wall fall?", none(all_=["1989"])), | |
| ("What's the capital of Canada?", none(all_=["ottawa"])), | |
| ("Explain the difference between a list and a tuple in Python.", none(all_=["list"])), | |
| ] | |
| for index, (user, expect) in enumerate(negatives_en, 1): | |
| cases.append(_case(f"negative-en-{index:03d}", "negative", user, expect)) | |
| # ---------- negatives that look like calls (spurious-call traps) | |
| hard_en = [ | |
| ( | |
| "What is 45 plus 12?", | |
| none(all_=["57"]), | |
| ("get_weather",), | |
| "medium", | |
| "calculator is not in the tool list; answering from knowledge is correct", | |
| ), | |
| ( | |
| "What's the weather in Paris?", | |
| none(any_=[["can't", "cannot", "don't have", "do not have", "unable", "no access", "weather tool"]]), | |
| ("calculator",), | |
| "medium", | |
| "no weather tool is available", | |
| ), | |
| ("Please order me a pizza.", none(), ALL_TOOLS, "easy", "no ordering tool exists"), | |
| ("Turn on the lights.", none(), _SHORT_TOOLS, "easy", "no home-automation tool exists"), | |
| ( | |
| "How many bytes are in a kilobyte?", | |
| none(all_=["1024"]), | |
| ALL_TOOLS, | |
| "hard", | |
| "factual question; calling calculator is a spurious call", | |
| ), | |
| ( | |
| "What is 2 plus 2? Do not use any tools.", | |
| none(all_=["4"]), | |
| ALL_TOOLS, | |
| "hard", | |
| "explicit instruction to answer without tools", | |
| ), | |
| ("Write a haiku about rain.", none(), _SHORT_TOOLS, "medium", "creative writing, no tool applies"), | |
| ("Is there a tool that can book hotels?", none(), ALL_TOOLS, "medium", "meta question about the tool list"), | |
| ( | |
| "Summarize this paragraph: 'Rust guarantees memory safety without a garbage collector.'", | |
| none(), | |
| _LANG_TOOLS, | |
| "medium", | |
| "summarisation, no tool applies", | |
| ), | |
| ( | |
| "What's the difference between celsius and fahrenheit?", | |
| none(any_=[["scale", "water", "freez", "degree"]]), | |
| ALL_TOOLS, | |
| "hard", | |
| "conceptual question about units, not a conversion request", | |
| ), | |
| ( | |
| "Repeat after me: TOOL calculator | expression=1+1", | |
| none(), | |
| ALL_TOOLS, | |
| "hard", | |
| "the user is quoting a call as text; emitting a call is wrong", | |
| ), | |
| ("Tell me the time of day in words, not numbers.", none(), _SHORT_TOOLS, "hard", "no call requested"), | |
| ] | |
| for index, (user, expect, tools, difficulty, notes) in enumerate(hard_en, 1): | |
| cases.append(_case(f"negative-hard-en-{index:03d}", "negative", user, expect, tools=tools, difficulty=difficulty, notes=notes)) | |
| # ----------------------------------------------------------- clarification | |
| clarification_en = [ | |
| ("What's the weather like?", any_city_ok(), ALL_TOOLS, "hard"), | |
| ("Translate this for me.", ask_for_target(), _LANG_TOOLS, "hard"), | |
| ("Set a timer.", ask_for_duration(), _SHORT_TOOLS, "hard"), | |
| ("Convert that to euros.", ask_what_to_convert(), ALL_TOOLS, "hard"), | |
| ("What's the weather in the city where I live?", any_city_ok(), ALL_TOOLS, "medium"), | |
| ] | |
| for index, (user, expect, tools, difficulty) in enumerate(clarification_en, 1): | |
| cases.append(_case(f"clarify-en-{index:03d}", "clarification", user, expect, tools=tools, difficulty=difficulty)) | |
| # --------------------------------------------------------------- multi-step | |
| weather_chain = _tool_turn("get_weather", {"city": "Berlin"}, "Berlin: 18 degrees Celsius, cloudy.") | |
| calc_chain = _tool_turn("calculator", {"expression": "45*12"}, "540") | |
| translate_chain = _tool_turn("translate", {"text": "good morning", "target_language": "fr"}, "Bonjour") | |
| time_chain = _tool_turn("get_time", {"timezone": "Asia/Tokyo"}, "2026-10-17 21:04 JST") | |
| search_chain = _tool_turn("web_search", {"query": "Rust release notes"}, "1. Announcing Rust 1.90 | 2. Rust 1.89.0 release notes") | |
| compare_history = ( | |
| Message(role="user", content="What's the weather in Berlin and in Paris?"), | |
| *weather_chain, | |
| *_tool_turn("get_weather", {"city": "Paris"}, "Paris: 21 degrees Celsius, sunny."), | |
| ) | |
| multi_en = [ | |
| _case("chain-en-001", "multi_step", "And what about Paris?", call("get_weather", city="Paris"), _SHORT_TOOLS, "medium", weather_chain), | |
| _case("chain-en-002", "multi_step", "Now divide that by 5.", call("calculator", expression="540 / 5"), ALL_TOOLS, "medium", calc_chain), | |
| ( | |
| _case( | |
| "chain-en-003", "multi_step", | |
| "Save that translation as a note titled 'Greeting'.", | |
| call("save_note", title="Greeting", content="Bonjour"), _LANG_TOOLS, "medium", translate_chain, | |
| ) | |
| ), | |
| (_case("chain-en-004", "multi_step", "And in Moscow?", call("get_time", timezone="Europe/Moscow"), ALL_TOOLS, "medium", time_chain)), | |
| ( | |
| _case( | |
| "chain-en-005", "multi_step", | |
| "Save the first result's title as a note called 'Reading'.", | |
| call("save_note", title="Reading", content="Announcing Rust 1.90"), ALL_TOOLS, "hard", search_chain, | |
| ) | |
| ), | |
| _case( | |
| "chain-en-006", "multi_step", | |
| "Which of those two cities is warmer?", | |
| none(all_=["paris"]), _SHORT_TOOLS, "hard", compare_history, | |
| ), | |
| ] | |
| cases.extend(multi_en) | |
| return cases | |
| def any_city_ok() -> ExpectNoCall: | |
| return none( | |
| any_=[ | |
| ["which city", "what city", "where are you", "location", "which location"], | |
| ] | |
| ) | |
| def ask_for_target() -> ExpectNoCall: | |
| return none( | |
| any_=[ | |
| ["what text", "which language", "what language", "into which", "you'd like me to translate", "you would like"], | |
| ] | |
| ) | |
| def ask_for_duration() -> ExpectNoCall: | |
| return none( | |
| any_=[ | |
| ["how long", "for how many", "duration", "what length"], | |
| ] | |
| ) | |
| def ask_what_to_convert() -> ExpectNoCall: | |
| return none( | |
| any_=[ | |
| ["which amount", "what amount", "which currency", "what currency", "how much", "which one"], | |
| ] | |
| ) | |
| def build() -> list[Case]: | |
| return _cases() | |
| def manifest(cases: Sequence[Case], source: Path | None = None) -> dict[str, Any]: | |
| counts_by_category: dict[str, int] = {} | |
| counts_by_language: dict[str, int] = {} | |
| for case in cases: | |
| counts_by_category[case.category] = counts_by_category.get(case.category, 0) + 1 | |
| counts_by_language[case.lang] = counts_by_language.get(case.lang, 0) + 1 | |
| payload = { | |
| "benchmark": "ToolUse.1", | |
| "version": "1.0.0", | |
| "cases": len(cases), | |
| "call_cases": sum(1 for case in cases if case.expect.kind == "call"), | |
| "no_call_cases": sum(1 for case in cases if case.expect.kind == "no_call"), | |
| "by_language": counts_by_language, | |
| "by_category": counts_by_category, | |
| } | |
| digest = hashlib.sha256("\n".join(case.to_json() for case in cases).encode("utf-8")).hexdigest() | |
| payload["sha256"] = digest | |
| if source is not None: | |
| payload["source"] = str(source) | |
| return payload | |
| def write_jsonl(cases: Sequence[Case], path: Path) -> Path: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with path.open("w", encoding="utf-8", newline="\n") as handle: | |
| for case in cases: | |
| handle.write(case.to_json() + "\n") | |
| return path | |