-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_manager.py
More file actions
50 lines (45 loc) · 1.53 KB
/
settings_manager.py
File metadata and controls
50 lines (45 loc) · 1.53 KB
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
import json
from pathlib import Path
from logger_config import logger
SETTINGS_FILE = Path(__file__).parent / "settings.json"
# Default settings in case the file doesn't exist yet
DEFAULT_SETTINGS = {
"active_provider": "Mistral",
"api_keys": {
"Mistral": "",
"OpenAI": "",
"Gemini": "",
"Claude": ""
},
"models": {
"Mistral": "open-mistral-7b",
"OpenAI": "gpt-3.5-turbo",
"Gemini": "gemini-2.5-flash-lite",
"Claude": "claude-3-haiku-20240307"
}
}
def load_settings():
"""Loads settings from the JSON file, or returns defaults if missing."""
if not SETTINGS_FILE.exists():
save_settings(DEFAULT_SETTINGS)
return DEFAULT_SETTINGS
try:
with open(SETTINGS_FILE, 'r') as f:
settings = json.load(f)
# Ensure all necessary keys exist (in case of partial updates)
for key, value in DEFAULT_SETTINGS.items():
if key not in settings:
settings[key] = value
return settings
except Exception as e:
logger.error(f"Error loading settings: {e}")
return DEFAULT_SETTINGS
def save_settings(settings_data):
"""Saves the provided settings dictionary to the JSON file."""
try:
with open(SETTINGS_FILE, 'w') as f:
json.dump(settings_data, f, indent=4)
return True
except Exception as e:
logger.error(f"Error saving settings: {e}")
return False