Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def multi_turn_runner(
multi_turn_ground_truth_list: list[list[str]] = possible_answer[i]["ground_truth"]
test_entry: dict = prompt[i]

# Remove the function doc from the score file for better readability; they are repeated and way too long
if "function" in test_entry:
del test_entry["function"]

if type(multi_turn_model_result_list) != list:
result.append(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@ def write_list_of_dicts_to_file(filename, data, subdir=None):
with open(filename, "w") as f:
for i, entry in enumerate(data):
# Go through each key-value pair in the dictionary to make sure the values are JSON serializable
for key, value in entry.items():
try:
json.dumps(value)
except:
# If the value is not JSON serializable, wrap it in a string
entry[key] = str(value)

entry = make_json_serializable(entry)
json_str = json.dumps(entry)
f.write(json_str)
if i < len(data) - 1:
f.write("\n")


def make_json_serializable(value):
if isinstance(value, dict):
# If the value is a dictionary, we need to go through each key-value pair recursively
return {k: make_json_serializable(v) for k, v in value.items()}
elif isinstance(value, list):
# If the value is a list, we need to process each element recursively
return [make_json_serializable(item) for item in value]
else:
# Try to serialize the value directly, and if it fails, convert it to a string
try:
json.dumps(value)
return value
except (TypeError, ValueError):
return str(value)


def is_function_calling_format_output(decoded_output):
# Ensure the output is a list of dictionaries
if type(decoded_output) == list:
Expand Down
Loading