Repository navigation
feat(e2e): Add BFCL v3 function calling test infrastructure #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
51f559d
feat(bfcl): add BFCL v3 test infrastructure
vschandramourya 0900457
feat(bfcl): add BFCL pytest test classes
vschandramourya 6c5bc3a
refactor(bfcl): address review feedback
vschandramourya c091618
remove bfcl logs from being tracked
vschandramourya 6adf41f
Remove the baseline comparision code
vschandramourya 5d9d32d
add pytest marker for GPU-dependent workers
vschandramourya de0bfdc
Replace module-level _all_cases with pytest_generate_tests for lazy l…
vschandramourya 7c52ebd
fix(bfcl): thread-safe result collection and proper session lifecycle…
vschandramourya 4cb86fc
fix(bfcl): replace set_run_dir with get_or_create_run_dir avoiding em…
vschandramourya 4561812
lint fix
vschandramourya 764fd7e
test(bfcl): improve data downloading and loader fail-fast behavior
vschandramourya ea384a9
test(bfcl): tighten evaluator validation
vschandramourya 88b1a98
fix(bfcl): fix session teardown issue
vschandramourya b1a4318
fix(bfcl): resolve mypy issues in evaluator
vschandramourya 44f12b5
test(e2e)mark standalone BFCL suite as e2e
vschandramourya 056ad64
fix(e2e) keep all ignored files at one place
vschandramourya e52b7ab
fix(e2e) correct the file imports and fail gracefully
vschandramourya 17f3b98
refactor(bfcl): move response helpers from test file into bfcl package
vschandramourya d6e0244
Merge branch 'main' into feat/bfcl-test-infrastructure
vschandramourya 6ef5353
Merge branch 'main' into feat/bfcl-test-infrastructure
vschandramourya 29bc201
refactor(bfcl): convert case dict to BFCLCase dataclass
vschandramourya f4a1df0
Merge branch 'main' into feat/bfcl-test-infrastructure
vschandramourya 5981cf3
Update e2e_test/bfcl/converter.py
vschandramourya ecb0361
Merge branch 'main' into feat/bfcl-test-infrastructure
vschandramourya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """BFCL (Berkeley Function Calling Leaderboard) test infrastructure. | ||
|
|
||
| Provides data loading, evaluation, and per-test logging for open-source | ||
| BFCL v3 test cases run against the SMG gateway. | ||
| """ | ||
|
|
||
| from .converter import bfcl_to_openai_tools | ||
| from .evaluator import BFCLEvaluator, extract_tool_calls, log_file_for_summary | ||
| from .loader import ( | ||
| BFCL_CATEGORIES, | ||
| BFCLCase, | ||
| MissingBFCLAnswerFileError, | ||
| load_bfcl_category, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "BFCL_CATEGORIES", | ||
| "BFCLCase", | ||
| "BFCLEvaluator", | ||
| "MissingBFCLAnswerFileError", | ||
| "bfcl_to_openai_tools", | ||
| "extract_tool_calls", | ||
| "load_bfcl_category", | ||
| "log_file_for_summary", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||||||
| """BFCL-to-OpenAI format converter. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Converts BFCL function definitions to OpenAI-compatible tool calling format, | ||||||||||||||||||||||
| handling BFCL-specific schema quirks (non-standard JSON Schema types). | ||||||||||||||||||||||
| """ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def _fix_parameter_type(params: dict) -> dict: | ||||||||||||||||||||||
| """Convert BFCL's non-standard types to valid JSON Schema types recursively.""" | ||||||||||||||||||||||
| result = dict(params) | ||||||||||||||||||||||
| ptype = result.get("type") | ||||||||||||||||||||||
| if ptype == "dict": | ||||||||||||||||||||||
| result["type"] = "object" | ||||||||||||||||||||||
| elif ptype == "float": | ||||||||||||||||||||||
| result["type"] = "number" | ||||||||||||||||||||||
| elif ptype == "int": | ||||||||||||||||||||||
| result["type"] = "integer" | ||||||||||||||||||||||
| elif ptype in ("list", "tuple"): | ||||||||||||||||||||||
| result["type"] = "array" | ||||||||||||||||||||||
| props = result.get("properties") | ||||||||||||||||||||||
| if isinstance(props, dict): | ||||||||||||||||||||||
| result["properties"] = { | ||||||||||||||||||||||
| k: _fix_parameter_type(v) if isinstance(v, dict) else v for k, v in props.items() | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| items = result.get("items") | ||||||||||||||||||||||
| if isinstance(items, dict): | ||||||||||||||||||||||
| result["items"] = _fix_parameter_type(items) | ||||||||||||||||||||||
| return result | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def bfcl_to_openai_tools(bfcl_functions: list[dict]) -> list[dict]: | ||||||||||||||||||||||
| """Convert BFCL function definitions to OpenAI tools format. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Handles the BFCL-specific quirks: | ||||||||||||||||||||||
| - parameters.type "dict" → "object" | ||||||||||||||||||||||
| - parameters.type "float" → "number" | ||||||||||||||||||||||
| - Wraps in {"type": "function", "function": ...} | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Nit: The docstring still only mentions
Suggested change
|
||||||||||||||||||||||
| """ | ||||||||||||||||||||||
| tools = [] | ||||||||||||||||||||||
| for fn in bfcl_functions: | ||||||||||||||||||||||
| fixed_fn = dict(fn) | ||||||||||||||||||||||
| if "parameters" in fixed_fn: | ||||||||||||||||||||||
| fixed_fn["parameters"] = _fix_parameter_type(fixed_fn["parameters"]) | ||||||||||||||||||||||
| tools.append({"type": "function", "function": fixed_fn}) | ||||||||||||||||||||||
| return tools | ||||||||||||||||||||||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env python3 | ||
| """Download BFCL v3 open-source test data from HuggingFace. | ||
|
|
||
| Usage: | ||
| python e2e_test/bfcl/download_data.py | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| HF_BASE = ( | ||
| "https://huggingface.co/datasets/gorilla-llm/Berkeley-Function-Calling-Leaderboard/resolve/main" | ||
| ) | ||
|
|
||
| DATA_DIR = Path(__file__).parent / "data" | ||
| TIMEOUT_SECONDS = 60 | ||
|
|
||
| FILES = [ | ||
| "BFCL_v3_simple.json", | ||
| "BFCL_v3_multiple.json", | ||
| "BFCL_v3_parallel.json", | ||
| "BFCL_v3_parallel_multiple.json", | ||
| "BFCL_v3_irrelevance.json", | ||
| ] | ||
|
|
||
| ANSWER_FILES = [ | ||
| ("possible_answer/BFCL_v3_simple.json", "BFCL_v3_simple_answer.json"), | ||
| ("possible_answer/BFCL_v3_multiple.json", "BFCL_v3_multiple_answer.json"), | ||
| ("possible_answer/BFCL_v3_parallel.json", "BFCL_v3_parallel_answer.json"), | ||
| ( | ||
| "possible_answer/BFCL_v3_parallel_multiple.json", | ||
| "BFCL_v3_parallel_multiple_answer.json", | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def _count_lines(path: Path) -> int: | ||
| with path.open(encoding="utf-8") as handle: | ||
| return sum(1 for _ in handle) | ||
|
|
||
|
|
||
| def _download_one(remote_path: str, local_name: str, *, force: bool = False) -> None: | ||
| url = f"{HF_BASE}/{remote_path}" | ||
| dest = DATA_DIR / local_name | ||
| if dest.exists() and not force: | ||
| print(f"Skipping {local_name} (already downloaded)") | ||
| print(f" -> {dest.name} ({_count_lines(dest)} entries)") | ||
| return | ||
|
|
||
| print(f"Downloading {local_name}...") | ||
| tmp = dest.with_suffix(dest.suffix + ".tmp") | ||
| try: | ||
| with urllib.request.urlopen(url, timeout=TIMEOUT_SECONDS) as resp, tmp.open("wb") as out: | ||
| shutil.copyfileobj(resp, out) | ||
| out.flush() | ||
| os.fsync(out.fileno()) | ||
| tmp.replace(dest) | ||
| finally: | ||
| if tmp.exists(): | ||
| tmp.unlink() | ||
|
|
||
| lines = _count_lines(dest) | ||
| print(f" → {dest.name} ({lines} entries)") | ||
|
|
||
|
|
||
| def download(*, force_redownload: bool = False) -> None: | ||
| DATA_DIR.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| for fname in FILES: | ||
| _download_one(fname, fname, force=force_redownload) | ||
|
|
||
| for remote_path, local_name in ANSWER_FILES: | ||
| _download_one(remote_path, local_name, force=force_redownload) | ||
|
|
||
| print("\nDone. All BFCL v3 data downloaded.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| download() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.