Config
Browse files- config.yaml.example +5 -2
- src/config.py +19 -7
config.yaml.example
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# API and Token configurations
|
2 |
-
# api_token: YOUR_API_TOKEN_HERE #
|
3 |
queue_repo: stacklok/requests
|
4 |
|
5 |
# File paths
|
@@ -20,6 +20,9 @@ log_level: INFO
|
|
20 |
# Evaluation configurations
|
21 |
evaluation_wait_time: 60 # minutes
|
22 |
|
|
|
|
|
|
|
23 |
# Note: All of these values can be overridden by environment variables.
|
24 |
# The corresponding environment variable names are:
|
25 |
-
# API_TOKEN, QUEUE_REPO, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, LOG_LEVEL, EVALUATION_WAIT_TIME
|
|
|
1 |
# API and Token configurations
|
2 |
+
# api_token: YOUR_API_TOKEN_HERE # Required only for local runs. Set this or use API_TOKEN environment variable.
|
3 |
queue_repo: stacklok/requests
|
4 |
|
5 |
# File paths
|
|
|
20 |
# Evaluation configurations
|
21 |
evaluation_wait_time: 60 # minutes
|
22 |
|
23 |
+
# Environment type
|
24 |
+
is_local: false # Set to true for local runs, false for Hugging Face deployment
|
25 |
+
|
26 |
# Note: All of these values can be overridden by environment variables.
|
27 |
# The corresponding environment variable names are:
|
28 |
+
# API_TOKEN, QUEUE_REPO, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, LOG_LEVEL, EVALUATION_WAIT_TIME, IS_LOCAL
|
src/config.py
CHANGED
@@ -11,7 +11,8 @@ def load_config() -> Dict[str, Any]:
|
|
11 |
'allowed_weight_types': ['Safetensors', 'PyTorch', 'GGUF', 'Other'],
|
12 |
'default_revision': 'main',
|
13 |
'log_level': 'INFO',
|
14 |
-
'evaluation_wait_time': 60
|
|
|
15 |
}
|
16 |
|
17 |
# Load from config.yaml if it exists
|
@@ -27,23 +28,31 @@ def load_config() -> Dict[str, Any]:
|
|
27 |
'EVAL_REQUESTS_PATH': 'eval_requests_path',
|
28 |
'EVAL_RESULTS_PATH': 'eval_results_path',
|
29 |
'LOG_LEVEL': 'log_level',
|
30 |
-
'EVALUATION_WAIT_TIME': 'evaluation_wait_time'
|
|
|
31 |
}
|
32 |
|
33 |
for env_var, config_key in env_vars.items():
|
34 |
if os.environ.get(env_var):
|
35 |
config[config_key] = os.environ[env_var]
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
return config
|
42 |
|
43 |
config = load_config()
|
44 |
|
45 |
-
# API and Token configurations
|
46 |
-
API_TOKEN: str = config
|
47 |
QUEUE_REPO: str = config['queue_repo']
|
48 |
|
49 |
# File paths
|
@@ -59,3 +68,6 @@ LOG_LEVEL: str = config['log_level']
|
|
59 |
|
60 |
# Evaluation configurations
|
61 |
EVALUATION_WAIT_TIME: int = config['evaluation_wait_time']
|
|
|
|
|
|
|
|
11 |
'allowed_weight_types': ['Safetensors', 'PyTorch', 'GGUF', 'Other'],
|
12 |
'default_revision': 'main',
|
13 |
'log_level': 'INFO',
|
14 |
+
'evaluation_wait_time': 60,
|
15 |
+
'is_local': False # Default to non-local (Hugging Face) environment
|
16 |
}
|
17 |
|
18 |
# Load from config.yaml if it exists
|
|
|
28 |
'EVAL_REQUESTS_PATH': 'eval_requests_path',
|
29 |
'EVAL_RESULTS_PATH': 'eval_results_path',
|
30 |
'LOG_LEVEL': 'log_level',
|
31 |
+
'EVALUATION_WAIT_TIME': 'evaluation_wait_time',
|
32 |
+
'IS_LOCAL': 'is_local'
|
33 |
}
|
34 |
|
35 |
for env_var, config_key in env_vars.items():
|
36 |
if os.environ.get(env_var):
|
37 |
config[config_key] = os.environ[env_var]
|
38 |
|
39 |
+
# Convert IS_LOCAL to boolean
|
40 |
+
config['is_local'] = config.get('is_local', '').lower() == 'true'
|
41 |
+
|
42 |
+
# Ensure API_TOKEN is set only for local runs
|
43 |
+
if config['is_local']:
|
44 |
+
if 'api_token' not in config or not config['api_token']:
|
45 |
+
raise ValueError("API_TOKEN must be set in environment variables or config.yaml for local runs")
|
46 |
+
else:
|
47 |
+
# Remove API_TOKEN for non-local runs
|
48 |
+
config.pop('api_token', None)
|
49 |
|
50 |
return config
|
51 |
|
52 |
config = load_config()
|
53 |
|
54 |
+
# API and Token configurations (only for local runs)
|
55 |
+
API_TOKEN: str = config.get('api_token', '')
|
56 |
QUEUE_REPO: str = config['queue_repo']
|
57 |
|
58 |
# File paths
|
|
|
68 |
|
69 |
# Evaluation configurations
|
70 |
EVALUATION_WAIT_TIME: int = config['evaluation_wait_time']
|
71 |
+
|
72 |
+
# Environment type
|
73 |
+
IS_LOCAL: bool = config['is_local']
|