Files
banban/talkingq-url/services/config_manager.py
2026-03-24 15:04:36 +08:00

49 lines
1.8 KiB
Python

from typing import Any, Dict
from config import settings
class ConfigManager:
"""统一的配置管理服务,处理全局配置和角色特定配置的优先级"""
@staticmethod
def get_config_value(config_key: str, role_config: Dict[str, Any] = None, default_value: Any = None) -> Any:
"""
获取配置值,遵循优先级:角色配置 > 全局配置 > 默认值
Args:
config_key: 配置键名
role_config: 角色配置字典
default_value: 默认值,当角色配置和全局配置都没有该键时返回
"""
if role_config and config_key in role_config:
return role_config[config_key]
if hasattr(settings, config_key):
return getattr(settings, config_key)
return default_value
@staticmethod
def get_service_config(service_type: str, role_config: Dict[str, Any] = None) -> Dict[str, Any]:
"""
获取服务特定配置,整合角色配置和全局配置
Args:
service_type: 服务类型 (asr, llm, tts)
role_config: 角色配置字典
"""
config = {}
config_mapping = {
'asr': {
'provider': 'asr_provider',
},
'llm': {
'provider': 'llm_provider',
'model_id': 'volcano_model_id',
},
'tts': {
'provider': 'tts_provider',
'voice_type': 'minimax_voice_id',
}
}
for config_key, setting_key in config_mapping.get(service_type, {}).items():
if setting_key:
config[config_key] = ConfigManager.get_config_value(setting_key, role_config)
return config
config_manager = ConfigManager()