from dataclasses import dataclass from pathlib import Path from omegaconf import OmegaConf # 日志配置 @dataclass class File: enable: bool level: str path: str rotation: str retention: str @dataclass class Console: enable: bool level: str @dataclass class LoggingConfig: file: File console: Console # 数据库配置 @dataclass class DBConfig: host: str port: int user: str password: str database: str @dataclass class EmbeddingConfig: host: str port: int model: str @dataclass class MilvusConfig: host: str port: int user: str password: str embedding_size: int @dataclass class LLMConfig: model_name: str api_key: str base_url: str @dataclass class ASRConfig: model_name: str api_key: str base_url: str @dataclass class RedisConfig: host: str port: int password: str db: int = 0 decode_responses: bool = True @dataclass class AppConfig: logging: LoggingConfig db_assistant: DBConfig embedding: EmbeddingConfig llm: LLMConfig milvus: MilvusConfig asr: ASRConfig redis: RedisConfig config_file = Path(__file__).parents[2] / 'conf' / 'app_config.yaml' context = OmegaConf.load(config_file) schema = OmegaConf.structured(AppConfig) app_config: AppConfig = OmegaConf.to_object(OmegaConf.merge(schema, context)) if __name__ == '__main__': print(app_config.db_assistant.host)