File size: 1,042 Bytes
a44bd4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45

import yaml
import json
import os
from box import Box
import re

MAX_INPUT_TOKEN_NUM = 128000

def load_config(config_path):
    config = Box.from_yaml(
        filename=config_path, Loader=yaml.FullLoader)
    return config



def save_as_json(path, data):
    '''
    outout a json file with indent equals to 2
    '''
    json_data = json.dumps(data, indent=2)
    # Save JSON to a file
    try:
        # Create the directory structure if it doesn't exist
        os.makedirs(os.path.dirname(path), exist_ok=True)

        # Write data to the JSON file
        with open(path, 'w') as json_file:
            json_file.write(json_data)

        print(f"Experiment results written to '{path}' successfully.")

        class ContextAttributeError(BaseException):
            def __init__(self, message):
                self.message = message
                super().__init__(self.message)

        return True
    except Exception as e:
        print(f"Failed to write experiment results to '{path}': {e}")
        return False

    pass