File size: 1,683 Bytes
4d1746c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)