Repository: microsoft/promptbase
File: src/promptbase/bigbench/bigbench_cot.py (Python)

Code before:
    cot_prompts_dir = bigbench_data_root / "cot-prompts"
    bbh_test_dir = bigbench_data_root / "bbh"
    generations_dir = get_generations_path()

    if not os.path.exists(cot_prompts_dir):
        print(f"COT prompt directory {cot_prompts_dir} does not exist")
        exit(1)
    elif not os.path.exists(bbh_test_dir):
        print(f"BBH test directory {bbh_test_dir} does not exist")
        exit(1)

    print(f"Processing CoT for BigBench subjects: {subjects}")

    threads = []
    for subject in subjects:
        bbh_test_path = bbh_test_dir / f"{subject}.json"
        cot_prompt_path = cot_prompts_dir / f"{subject}.txt"
        if not os.path.exists(bbh_test_path):
            print(f"Data file {bbh_test_path} does not exist")
        elif not os.path.exists(cot_prompt_path):
            print(f"COT prompt file {cot_prompt_path} does not exist")

        if api_type == "completion":
            _logger.info(f"Starting completion thread for {bbh_test_path}")
            results_path = generations_dir / "bigbench" / "cot_results" / "completion"
            os.makedirs(results_path, exist_ok=True)
            thread = threading.Thread(
                target=do_completion_cot,
                args=(bbh_test_path, cot_prompt_path, subject, results_path),
            )
        else:
            _logger.info(f"Starting chat thread for {bbh_test_path}")
            results_path = generations_dir / "bigbench" / "cot_results" / "chat"
            os.makedirs(results_path, exist_ok=True)
            thread = threading.Thread(
                target=do_chat_cot,
                args=(bbh_test_path, cot_prompt_path, subject, results_path),
            )
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()

    print("Done!")


Review comment (suggestion):
If `results_path` is a `pathlib.Path` object, there is a 'mkdir' (or something like that) method on it

Code after:
    cot_prompts_dir = bigbench_data_root / "cot-prompts"
    bbh_test_dir = bigbench_data_root / "bbh"
    generations_dir = get_generations_path()

    if not os.path.exists(cot_prompts_dir):
        print(f"COT prompt directory {cot_prompts_dir} does not exist")
        exit(1)
    elif not os.path.exists(bbh_test_dir):
        print(f"BBH test directory {bbh_test_dir} does not exist")
        exit(1)

    print(f"Processing CoT for BigBench subjects: {subjects}")

    threads = []
    for subject in subjects:
        bbh_test_path = bbh_test_dir / f"{subject}.json"
        cot_prompt_path = cot_prompts_dir / f"{subject}.txt"
        if not os.path.exists(bbh_test_path):
            print(f"Data file {bbh_test_path} does not exist")
        elif not os.path.exists(cot_prompt_path):
            print(f"COT prompt file {cot_prompt_path} does not exist")

        if api_type == "completion":
            _logger.info(f"Starting completion thread for {bbh_test_path}")
            results_path = generations_dir / "bigbench" / "cot_results" / "completion"
            os.makedirs(results_path, exist_ok=True)
            thread = threading.Thread(
                target=do_completion_cot,
                args=(bbh_test_path, cot_prompt_path, subject, results_path),
            )
        else:
            _logger.info(f"Starting chat thread for {bbh_test_path}")
            results_path = generations_dir / "bigbench" / "cot_results" / "chat"
            results_path.mkdir(parents=True, exist_ok=True)
            thread = threading.Thread(
                target=do_chat_cot,
                args=(bbh_test_path, cot_prompt_path, subject, results_path),
            )
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()

    print("Done!")