Skip to content

Commit 893c9af

Browse files
committed
Make eval_checker consistent with main branch by merging (ShishirPatil#496)
1 parent f736521 commit 893c9af

File tree

5 files changed

+607
-535
lines changed

5 files changed

+607
-535
lines changed

berkeley-function-call-leaderboard/bfcl/eval_checker/checker.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from js_type_converter import js_type_converter
2-
from java_type_converter import java_type_converter
31
from model_handler.constant import (
42
UNDERSCORE_TO_DOT,
53
JAVA_TYPE_CONVERSION,
@@ -12,6 +10,11 @@
1210
import time
1311
import json
1412

13+
# We switch to conditional import for the following two imports to avoid unnecessary installations.
14+
# User doesn't need to setup the tree-sitter packages if they are not running the test for that language.
15+
# from js_type_converter import js_type_converter
16+
# from java_type_converter import java_type_converter
17+
1518
PYTHON_TYPE_MAPPING = {
1619
"string": str,
1720
"integer": int,
@@ -362,9 +365,19 @@ def simple_function_checker(
362365
nested_type_converted = None
363366

364367
if language == "Java":
368+
from java_type_converter import java_type_converter
369+
365370
expected_type_converted = JAVA_TYPE_CONVERSION[expected_type_description]
366371

367372
if expected_type_description in JAVA_TYPE_CONVERSION:
373+
if type(value) != str:
374+
result["valid"] = False
375+
result["error"].append(
376+
f"Incorrect type for parameter {repr(param)}. Expected type String, got {type(value).__name__}. Parameter value: {repr(value)}."
377+
)
378+
result["error_type"] = "type_error:java"
379+
return result
380+
368381
if expected_type_description in NESTED_CONVERSION_TYPE_LIST:
369382
nested_type = param_details[param]["items"]["type"]
370383
nested_type_converted = JAVA_TYPE_CONVERSION[nested_type]
@@ -375,9 +388,19 @@ def simple_function_checker(
375388
value = java_type_converter(value, expected_type_description)
376389

377390
elif language == "JavaScript":
391+
from js_type_converter import js_type_converter
392+
378393
expected_type_converted = JS_TYPE_CONVERSION[expected_type_description]
379394

380395
if expected_type_description in JS_TYPE_CONVERSION:
396+
if type(value) != str:
397+
result["valid"] = False
398+
result["error"].append(
399+
f"Incorrect type for parameter {repr(param)}. Expected type String, got {type(value).__name__}. Parameter value: {repr(value)}."
400+
)
401+
result["error_type"] = "type_error:js"
402+
return result
403+
381404
if expected_type_description in NESTED_CONVERSION_TYPE_LIST:
382405
nested_type = param_details[param]["items"]["type"]
383406
nested_type_converted = JS_TYPE_CONVERSION[nested_type]
@@ -945,4 +968,4 @@ def exec_checker(decoded_result: list, func_description: dict, test_category: st
945968
func_description["execution_result"][0],
946969
func_description["execution_result_type"][0],
947970
False,
948-
)
971+
)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class NoAPIKeyError(Exception):
22
def __init__(self):
3-
self.message = "Please fill in the API keys in the function_credential_config.json file. If you do not provide the API keys, the executable test category results will be inaccurate."
3+
self.message = "❗️Please fill in the API keys in the function_credential_config.json file. If you do not provide the API keys, the executable test category results will be inaccurate."
44
super().__init__(self.message)
55

66

77
class BadAPIStatusError(Exception):
8-
def __init__(self, message):
9-
self.message = message
10-
super().__init__(self.message)
8+
def __init__(self, errors, error_rate):
9+
self.errors = errors
10+
self.error_rate = error_rate

0 commit comments

Comments
 (0)