def main():
    """
    This script takes the GPT-4 completion file with json object as the response format, where the returned json contains two fields:
    - feedback: the critique for the incorrect program.
    - corrected_program: the corrected program.

    THe inputs file is generated by `pp_critique_difficulty` script.
    :return:
    """
    parser = ArgumentParser()
    parser.add_argument("--completion_file", type=str)
    parser.add_argument("--output_file", type=str)
    parser.add_argument("--num_workers", type=int, default=4)
    args = parser.parse_args()

    if os.path.exists(args.completion_file):
        data = [json.loads(line) for line in open(args.completion_file).readlines()]
    else:
        data = []
        item_id2data_id = {}
        for file in glob(args.completion_file):
            print(file)
            tmp = [json.loads(line) for line in open(file).readlines()]
            for item in tmp:
                item_id = item["problem_id"]
                if item_id not in item_id2data_id:
                    item_id2data_id[item_id] = len(data)
                    data.append(item)
                else:
                    new_completions = item["completion"]
                    if isinstance(new_completions, str):
                        new_completions = [new_completions]

                    if isinstance(data[item_id2data_id[item_id]]["completion"], list):
                        data[item_id2data_id[item_id]]["completion"].extend(new_completions)
                    else:
                        data[item_id2data_id[item_id]]["completion"] = [data[item_id2data_id[item_id]]["completion"]] + new_completions

    new_data = []
    parsing_error = 0
    for item in tqdm(data):
        if isinstance(item["completion"], str):
            try:
                item["completion"] = json.loads(item["completion"])
            except:
                # print(f"Parsing error: {item['completion']}")
                parsing_error += 1
        if isinstance(item["completion"], dict):
            new_data.append(item)
    data = new_data
    print(f"Total number of items: {len(data)}")
    print(f"Total number of parsing error: {parsing_error}")

    missing = 0
    corr = 0
    corr_at_k = 0
    pbar = tqdm(data)

    outputs = []
    with ThreadPoolExecutor(max_workers=args.num_workers) as executor:
        futures = []
        for _input in pbar:
            future = executor.submit(_worker, _input)
            futures.append(future)
            pbar.update()

        for future in tqdm(as_completed(futures), total=len(futures), desc="Collecting results"):
            outputs.append(future.result())

    for item in outputs:
        if "res" in item:
            if item["res"][0] is True:
                corr += 1
            if any(item["res"]):
                corr_at_k += 1
        else:
            missing += 1

    print(f"Missing: {missing / len(outputs)}")
    print(f"Correct: {corr / len(outputs)}")
    print(f"Correct at k: {corr_at_k / len(outputs)}")
    json.dump(outputs, open(args.output_file, "w"), ensure_ascii=False, indent=2)

    This script takes the GPT-4 completion file with json object as the response format, where the returned json contains two fields:
    - feedback: the critique for the incorrect program.
    - corrected_program: the corrected program.

    THe inputs file is generated by `pp_critique_difficulty` script.
    :return:
    
PFPO/scripts/apps/solution_fail_extract_critique.py