import pandas as pd import json def open_json(filename): with open(filename, 'r') as file: data = [] for line in file: try: data.append(json.loads(line)) except json.JSONDecodeError as e: print(f"Error parsing line: {line}") print(f"Error message: {e}") return data def format_questions(question): questions = """
\n""" for i, q in enumerate(question): questions += f"

Turn {i + 1} Question:
\n {q[0]['content']}
\n" return questions def format_solutions(solution): solutions = """

""" for i, s in enumerate(solution): solutions += f"Turn {i+1} Response \n\n ```python\n" for c in s: solutions += c + "\n" solutions += "\n```\n\n" return solutions def process(df, questions, solutions): df['involved_classes'] = [questions[int(df['id'][i].split("_")[-1])]['involved_classes'] for i in df.index] df['question'] = [questions[int(df['id'][i].split("_")[-1])]['question'] for i in df.index] df['ground_truth'] = [solutions[int(df['id'][i].split("_")[-1])]['ground_truth'] for i in df.index] df['question'] = df['question'].apply(format_questions) df['ground_truth'] = df['ground_truth'].apply(format_solutions) return df api_info = pd.read_csv("api_info.csv") questions = open_json('BFCL_v3_multi_turn_base.json') solutions = open_json('BFCL_v3_multi_turn_base_sol.json') api_samples = pd.read_csv('samples_qa.csv') api_samples = process(api_samples, questions, solutions)