affableiq commited on
Commit
2a29bc8
·
verified ·
1 Parent(s): 430e6ad

Upload eval/probe_tools.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. eval/probe_tools.py +126 -0
eval/probe_tools.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Eyeball BTL-4 Compact's tool use before running the full BFCL gate.
3
+
4
+ Ten prompts covering the five behaviours BTL-3 Compact was scored on: a single
5
+ call, picking the right tool from several, two calls in parallel, two *different*
6
+ tools in parallel, and knowing when to make no call at all. Parallel-multiple is
7
+ the one to watch -- it was BTL-3 Compact's weakest category at 3/10.
8
+
9
+ Shares the system prompt and parser with bfcl_compact.py so what you see here is
10
+ what the benchmark will score.
11
+
12
+ python probe_tools.py # all ten
13
+ python probe_tools.py --ask "your question here"
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import json
19
+
20
+ from bfcl_compact import REPO, FILENAME, SYS, parse_tool_calls
21
+
22
+ TOOLS = [
23
+ {"name": "get_weather",
24
+ "description": "Get the current weather for a city.",
25
+ "parameters": {"type": "object", "properties": {
26
+ "city": {"type": "string", "description": "City name"},
27
+ "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}},
28
+ "required": ["city"]}},
29
+ {"name": "convert_currency",
30
+ "description": "Convert an amount between two currencies.",
31
+ "parameters": {"type": "object", "properties": {
32
+ "amount": {"type": "number"},
33
+ "from_currency": {"type": "string", "description": "ISO code, e.g. USD"},
34
+ "to_currency": {"type": "string", "description": "ISO code, e.g. EUR"}},
35
+ "required": ["amount", "from_currency", "to_currency"]}},
36
+ {"name": "search_flights",
37
+ "description": "Search available flights between two airports on a date.",
38
+ "parameters": {"type": "object", "properties": {
39
+ "origin": {"type": "string"}, "destination": {"type": "string"},
40
+ "date": {"type": "string", "description": "YYYY-MM-DD"}},
41
+ "required": ["origin", "destination", "date"]}},
42
+ {"name": "send_email",
43
+ "description": "Send an email.",
44
+ "parameters": {"type": "object", "properties": {
45
+ "to": {"type": "string"}, "subject": {"type": "string"},
46
+ "body": {"type": "string"}},
47
+ "required": ["to", "subject", "body"]}},
48
+ {"name": "stock_price",
49
+ "description": "Get the latest share price for a ticker symbol.",
50
+ "parameters": {"type": "object", "properties": {
51
+ "ticker": {"type": "string"}},
52
+ "required": ["ticker"]}},
53
+ ]
54
+
55
+ # (prompt, what a correct model should do) -- the expectation is for your eyes,
56
+ # nothing here is auto-scored.
57
+ PROBES = [
58
+ ("What's the weather in Lagos?",
59
+ "single: get_weather(city='Lagos')"),
60
+ ("How much is 250 US dollars in Japanese yen?",
61
+ "single, right tool from five: convert_currency"),
62
+ ("What's the weather in Lagos and in Tokyo?",
63
+ "parallel: get_weather twice"),
64
+ ("Give me the weather in Berlin and the share price of NVDA.",
65
+ "parallel-multiple: two DIFFERENT tools"),
66
+ ("Convert 100 GBP to EUR and 100 GBP to USD, and tell me Tesla's stock price.",
67
+ "parallel-multiple: three calls, two tools"),
68
+ ("Find me flights from LHR to CDG on 2026-09-14.",
69
+ "single with a date argument"),
70
+ ("Write me a haiku about the rain.",
71
+ "ABSTAIN: no tool applies"),
72
+ ("What do you think is the best programming language?",
73
+ "ABSTAIN: opinion, no tool"),
74
+ ("Email [email protected] with the subject 'Q3 numbers' saying the figures are approved.",
75
+ "single with three string args"),
76
+ ("What's the weather in Paris, and email it to [email protected] with subject 'Paris'?",
77
+ "parallel-multiple: get_weather + send_email"),
78
+ ]
79
+
80
+
81
+ def run(llm, question: str, expect: str | None = None) -> None:
82
+ msgs = [{"role": "system", "content": SYS + json.dumps(TOOLS)},
83
+ {"role": "user", "content": question}]
84
+ out = llm.create_chat_completion(messages=msgs, max_tokens=512, temperature=0.0)
85
+ raw = out["choices"][0]["message"].get("content") or ""
86
+ calls = parse_tool_calls(raw)
87
+
88
+ print(f"\n\033[1m❯ {question}\033[0m")
89
+ if expect:
90
+ print(f" \033[2mexpect: {expect}\033[0m")
91
+ if calls:
92
+ for c in calls:
93
+ args = ", ".join(f"{k}={v!r}" for k, v in c["arguments"].items())
94
+ print(f" \033[32m→ {c['name']}({args})\033[0m")
95
+ else:
96
+ body = " ".join(raw.split())[:200]
97
+ print(f" \033[33m→ no tool call\033[0m {body}")
98
+
99
+
100
+ def main() -> None:
101
+ ap = argparse.ArgumentParser()
102
+ ap.add_argument("--ask", help="run a single custom question")
103
+ ap.add_argument("--model", default=None, help="local .gguf path")
104
+ ap.add_argument("--ctx", type=int, default=8192)
105
+ args = ap.parse_args()
106
+
107
+ from llama_cpp import Llama
108
+ path = args.model
109
+ if path is None:
110
+ from huggingface_hub import hf_hub_download
111
+ path = hf_hub_download(repo_id=REPO, filename=FILENAME)
112
+
113
+ print("loading onto the GPU ...", flush=True)
114
+ llm = Llama(model_path=path, n_gpu_layers=-1, n_ctx=args.ctx, verbose=False)
115
+
116
+ if args.ask:
117
+ run(llm, args.ask)
118
+ return
119
+ for q, expect in PROBES:
120
+ run(llm, q, expect)
121
+ print("\n\033[2mparallel-multiple is the one that matters: BTL-3 Compact "
122
+ "scored 3/10 there.\033[0m")
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()