|
import yaml |
|
import os |
|
from typing import List, Dict, Any |
|
|
|
def load_config() -> Dict[str, Any]: |
|
|
|
config = { |
|
'queue_repo': 'stacklok/requests', |
|
'eval_requests_path': './eval-queue', |
|
'eval_results_path': './eval-results', |
|
'allowed_weight_types': ['Safetensors', 'PyTorch', 'GGUF', 'Other'], |
|
'default_revision': 'main', |
|
'log_level': 'INFO', |
|
'evaluation_wait_time': 60, |
|
'is_local': False |
|
} |
|
|
|
|
|
if os.path.exists('config.yaml'): |
|
with open('config.yaml', 'r') as file: |
|
yaml_config = yaml.safe_load(file) |
|
config.update(yaml_config) |
|
|
|
|
|
env_vars = { |
|
'API_TOKEN': 'api_token', |
|
'QUEUE_REPO': 'queue_repo', |
|
'EVAL_REQUESTS_PATH': 'eval_requests_path', |
|
'EVAL_RESULTS_PATH': 'eval_results_path', |
|
'LOG_LEVEL': 'log_level', |
|
'EVALUATION_WAIT_TIME': 'evaluation_wait_time', |
|
'IS_LOCAL': 'is_local' |
|
} |
|
|
|
for env_var, config_key in env_vars.items(): |
|
if os.environ.get(env_var): |
|
config[config_key] = os.environ[env_var] |
|
|
|
|
|
is_local = config.get('is_local', False) |
|
if isinstance(is_local, str): |
|
config['is_local'] = is_local.lower() == 'true' |
|
else: |
|
config['is_local'] = bool(is_local) |
|
|
|
|
|
if config['is_local']: |
|
if 'api_token' not in config or not config['api_token']: |
|
raise ValueError("API_TOKEN must be set in environment variables or config.yaml for local runs") |
|
else: |
|
|
|
config.pop('api_token', None) |
|
|
|
return config |
|
|
|
config = load_config() |
|
|
|
|
|
API_TOKEN: str = config.get('api_token', '') |
|
QUEUE_REPO: str = config['queue_repo'] |
|
|
|
|
|
EVAL_REQUESTS_PATH: str = config['eval_requests_path'] |
|
EVAL_RESULTS_PATH: str = config['eval_results_path'] |
|
|
|
|
|
ALLOWED_WEIGHT_TYPES: List[str] = config['allowed_weight_types'] |
|
DEFAULT_REVISION: str = config['default_revision'] |
|
|
|
|
|
LOG_LEVEL: str = config['log_level'] |
|
|
|
|
|
EVALUATION_WAIT_TIME: int = config['evaluation_wait_time'] |
|
|
|
|
|
IS_LOCAL: bool = config['is_local'] |
|
|