dual_window / info_table.py
Huanzhi (Hans) Mao
init
4d1746c
raw
history blame
1.68 kB
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 = """<div style="text-align: left; width: 500px;">\n"""
for i, q in enumerate(question):
questions += f"<p style='margin: 10px 0;'><b>Turn {i + 1} Question:</b> <br>\n {q[0]['content']}<br>\n"
return questions
def format_solutions(solution):
solutions = """<div style="text-align: left;">"""
for i, s in enumerate(solution):
solutions += f"<b>Turn {i+1} Response</b> \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)