Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/eval/tasks/bfcl/task_context/bfcl_evaluation_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ async def score(state: TaskState, target: Target) -> Score:

target_obj = state.metadata["target_obj"]

args_identical = tool_calls[0].arguments == target_obj["arguments"]
function_identical = tool_calls[0].function == target_obj["function"]
args_identical = function_identical and canonicalize(
tool_calls[0].function,
tool_calls[0].arguments,
state.metadata["tools"],
) == canonicalize(
target_obj["function"],
target_obj["arguments"],
state.metadata["tools"],
)
logger.info(
f"args: {tool_calls[0].arguments} == {target_obj['arguments']}\nfunction: {tool_calls[0].function} == {target_obj['function']}"
)
Expand All @@ -94,6 +102,25 @@ async def score(state: TaskState, target: Target) -> Score:
return score


def canonicalize(
function_name: str,
arguments: dict[str, Any],
tools: list[dict[str, Any]],
) -> dict[str, Any]:
"""Fill optional argument defaults before comparing tool calls."""
tool = next(tool for tool in tools if tool["name"] == function_name)
parameters = tool["parameters"]
required = set(parameters.get("required") or [])
defaults = {
name: schema["default"]
for name, schema in (parameters.get("properties") or {}).items()
if name not in required
and isinstance(schema, dict)
and "default" in schema
}
return defaults | arguments


def record_to_sample(record: dict[str, Any]) -> Sample:
assert len(record["question"]) == 1
assert len(record["ground_truth"]) == 1
Expand Down