-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathconfig.py
191 lines (140 loc) · 5.92 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import toml
import os
class Config:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance._load_config()
return cls._instance
def _load_config(self):
# If the config file doesn't exist, copy from the sample
if not os.path.exists("config.toml"):
with open("sample.config.toml", "r") as f_in, open("config.toml", "w+") as f_out:
f_out.write(f_in.read())
f_out.seek(0)
self.config = toml.load(f_out)
else:
# check if all the keys are present in the config file
with open("sample.config.toml", "r") as f:
sample_config = toml.load(f)
with open("config.toml", "r+") as f:
config = toml.load(f)
# Update the config with any missing keys and their keys of keys
for key, value in sample_config.items():
config.setdefault(key, value)
if isinstance(value, dict):
for sub_key, sub_value in value.items():
config[key].setdefault(sub_key, sub_value)
f.seek(0)
toml.dump(config, f)
f.truncate()
self.config = config
def get_config(self):
return self.config
def get_bing_api_endpoint(self):
return self.config["API_ENDPOINTS"]["BING"]
def get_bing_api_key(self):
return self.config["API_KEYS"]["BING"]
def get_google_search_api_key(self):
return self.config["API_KEYS"]["GOOGLE_SEARCH"]
def get_google_search_engine_id(self):
return self.config["API_KEYS"]["GOOGLE_SEARCH_ENGINE_ID"]
def get_google_search_api_endpoint(self):
return self.config["API_ENDPOINTS"]["GOOGLE"]
def get_ollama_api_endpoint(self):
return self.config["API_ENDPOINTS"]["OLLAMA"]
def get_claude_api_key(self):
return self.config["API_KEYS"]["CLAUDE"]
def get_openai_api_key(self):
return self.config["API_KEYS"]["OPENAI"]
def get_openai_api_base_url(self):
return self.config["API_ENDPOINTS"]["OPENAI"]
def get_gemini_api_key(self):
return self.config["API_KEYS"]["GEMINI"]
def get_mistral_api_key(self):
return self.config["API_KEYS"]["MISTRAL"]
def get_groq_api_key(self):
return self.config["API_KEYS"]["GROQ"]
def get_netlify_api_key(self):
return self.config["API_KEYS"]["NETLIFY"]
def get_sqlite_db(self):
return self.config["STORAGE"]["SQLITE_DB"]
def get_screenshots_dir(self):
return self.config["STORAGE"]["SCREENSHOTS_DIR"]
def get_pdfs_dir(self):
return self.config["STORAGE"]["PDFS_DIR"]
def get_projects_dir(self):
return self.config["STORAGE"]["PROJECTS_DIR"]
def get_logs_dir(self):
return self.config["STORAGE"]["LOGS_DIR"]
def get_repos_dir(self):
return self.config["STORAGE"]["REPOS_DIR"]
def get_blacklist_dir(self):
return self.config["CUSTOM"]["BLACKLIST_FOLDER"]
def get_timeout_inference(self):
return self.config["CUSTOM"]["TIMEOUT_INFERENCE"]
def get_logging_rest_api(self):
return self.config["LOGGING"]["LOG_REST_API"] == "true"
def get_logging_prompts(self):
return self.config["LOGGING"]["LOG_PROMPTS"] == "true"
def set_bing_api_key(self, key):
self.config["API_KEYS"]["BING"] = key
self.save_config()
def set_bing_api_endpoint(self, endpoint):
self.config["API_ENDPOINTS"]["BING"] = endpoint
self.save_config()
def set_google_search_api_key(self, key):
self.config["API_KEYS"]["GOOGLE_SEARCH"] = key
self.save_config()
def set_google_search_engine_id(self, key):
self.config["API_KEYS"]["GOOGLE_SEARCH_ENGINE_ID"] = key
self.save_config()
def set_google_search_api_endpoint(self, endpoint):
self.config["API_ENDPOINTS"]["GOOGLE_SEARCH"] = endpoint
self.save_config()
def set_ollama_api_endpoint(self, endpoint):
self.config["API_ENDPOINTS"]["OLLAMA"] = endpoint
self.save_config()
def set_claude_api_key(self, key):
self.config["API_KEYS"]["CLAUDE"] = key
self.save_config()
def set_openai_api_key(self, key):
self.config["API_KEYS"]["OPENAI"] = key
self.save_config()
def set_openai_api_endpoint(self,endpoint):
self.config["API_ENDPOINTS"]["OPENAI"] = endpoint
self.save_config()
def set_gemini_api_key(self, key):
self.config["API_KEYS"]["GEMINI"] = key
self.save_config()
def set_mistral_api_key(self, key):
self.config["API_KEYS"]["MISTRAL"] = key
self.save_config()
def set_groq_api_key(self, key):
self.config["API_KEYS"]["GROQ"] = key
self.save_config()
def set_netlify_api_key(self, key):
self.config["API_KEYS"]["NETLIFY"] = key
self.save_config()
def set_logging_rest_api(self, value):
self.config["LOGGING"]["LOG_REST_API"] = "true" if value else "false"
self.save_config()
def set_logging_prompts(self, value):
self.config["LOGGING"]["LOG_PROMPTS"] = "true" if value else "false"
self.save_config()
def set_blacklist_folder(self, value):
self.config["CUSTOM"]["BLACKLIST_FOLDER"] = value
self.save_config()
def set_timeout_inference(self, value):
self.config["CUSTOM"]["TIMEOUT_INFERENCE"] = value
self.save_config()
def save_config(self):
with open("config.toml", "w") as f:
toml.dump(self.config, f)
def update_config(self, data):
for key, value in data.items():
if key in self.config:
for sub_key, sub_value in value.items():
self.config[key][sub_key] = sub_value
self.save_config()