generated from CubeGPT/CubeAgents
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.py
60 lines (47 loc) · 1.77 KB
/
config.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import yaml
from log_writer import logger
def load_config():
"""
Loads the configuration from the 'config.yaml' file and sets the global variables accordingly.
If the 'GENERATE_MODEL' key in the configuration is set to 'gpt-4', it forces the use of 'gpt-4-turbo-preview'
as the value for the 'GENERATE_MODEL' key, since 'gpt-4' no longer supports json modes.
Returns:
None
"""
with open("config.yaml", "r") as conf:
config_content = yaml.safe_load(conf)
for key, value in config_content.items():
if key == "GENERATE_MODEL" and value == "gpt-4":
globals()[
key
] = "gpt-4-turbo-preview" # Force using gpt-4-turbo-preview if the user set the GENERATE_MODEL to gpt-4. Because gpt-4 is not longer supports json modes.
globals()[key] = value
logger(f"config: {key} -> {value}")
def edit_config(key, value):
"""
Edits the config file.
Args:
key (str): The key to edit.
value (str): The value to set.
Returns:
bool: True
"""
with open("config.yaml", "r") as conf:
config_content = conf.readlines()
with open("config.yaml", "w") as conf:
for line in config_content:
if line.startswith(key):
if value == True:
write_value = "True"
elif value == False:
write_value = "False"
else:
write_value = f'"{value}"'
if "#" in line:
conf.write(f"{key}: {write_value} # {line.split('#')[1]}\n")
else:
conf.write(f"{key}: {write_value}\n")
else:
conf.write(line)
return True
load_config()