Download scripts/calib_tools.py from Launch80/Qwopus3.8-27B-Coder-Flash-quality-eval: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/datasets/Launch80/Qwopus3.8-27B-Coder-Flash-quality-eval/resolve/main/scripts/calib_tools.py
- Command line
-
hf download hf://datasets/Launch80/Qwopus3.8-27B-Coder-Flash-quality-eval/scripts/calib_tools.py
-
curl -L -o calib_tools.py https://huggingface.co/datasets/Launch80/Qwopus3.8-27B-Coder-Flash-quality-eval/resolve/main/scripts/calib_tools.py
1.84 kB
| """Tool-call calibration conversations: NousResearch/hermes-function-calling-v1 (func-calling.json, | |
| rev dae3e1d), parsed into structured tool_calls and rendered through the model's own chat template | |
| with tools=, so the Hessians see the served <tools> system prompt and <tool_call><function=...> turns. | |
| No BFCL data. Import render(tok, path) -> list of rendered strings, in file order.""" | |
| import json, re | |
| CALL = re.compile(r"<tool_call>\s*(\{.*?\})\s*</tool_call>", re.S) | |
| RESP = re.compile(r"<tool_response>\s*(.*?)\s*</tool_response>", re.S) | |
| def convert(r): | |
| tools = json.loads(r["tools"]) if isinstance(r["tools"], str) else r["tools"] | |
| msgs = [] | |
| for m in r["conversations"]: | |
| v = m["value"] | |
| if m["from"] == "system": | |
| continue # the template writes its own tools system prompt | |
| if m["from"] == "human": | |
| msgs.append({"role": "user", "content": v}) | |
| elif m["from"] == "gpt": | |
| calls = [json.loads(c) for c in CALL.findall(v)] | |
| if calls: | |
| msgs.append({"role": "assistant", "content": CALL.sub("", v).strip(), | |
| "tool_calls": [{"type": "function", "function": {"name": c["name"], "arguments": c.get("arguments", {})}} for c in calls]}) | |
| else: | |
| msgs.append({"role": "assistant", "content": v}) | |
| elif m["from"] == "tool": | |
| for body in RESP.findall(v) or [v]: | |
| msgs.append({"role": "tool", "content": body}) | |
| return tools, msgs | |
| def render(tok, path, **kw): | |
| out = [] | |
| for r in json.load(open(path)): | |
| try: | |
| tools, msgs = convert(r) | |
| out.append(tok.apply_chat_template(msgs, tools=tools, tokenize=False, **kw)) | |
| except (ValueError, KeyError, TypeError, json.JSONDecodeError): | |
| continue | |
| return out | |