-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
40 lines (34 loc) · 1.5 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
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
class Config:
def __init__(self):
self.discord_token = self._get_env('DISCORD_TOKEN')
self.full_log = os.getenv('FULL_LOG', 'false').lower() == 'true'
self.model_path = self._validate_path(os.getenv('MODEL_PATH'))
self.system_prompt = os.getenv('SYSTEM_PROMPT', 'You are a helpful assistant')
self.history_limit = int(os.getenv('HISTORY_LIMIT', 3))
self.stream_mode = os.getenv('STREAM_MODE', 'false').lower() == 'true'
self.model_params = {
'n_ctx': int(os.getenv('MODEL_N_CTX', 1024)),
'n_gpu_layers': int(os.getenv('GPU_LAYERS', 0)),
'max_tokens': int(os.getenv('MAX_TOKENS', 256)),
'temperature': float(os.getenv('TEMPERATURE', 0.7)),
'top_k': int(os.getenv('TOP_K', 40)),
'top_p': float(os.getenv('TOP_P', 0.95)),
'repeat_penalty': float(os.getenv('REPEAT_PENALTY', 1.1))
}
self.bot_config = {
'only_dm': os.getenv('ONLY_DM', 'true').lower() == 'true',
'command_prefix': os.getenv('COMMAND_PREFIX', '!')
}
def _get_env(self, name):
value = os.getenv(name)
if not value:
raise ValueError(f"Missing required env var: {name}")
return value
def _validate_path(self, path):
if not Path(path).exists():
raise FileNotFoundError(f"Model file not found: {path}")
return path