99 lines
1.7 KiB
Python
99 lines
1.7 KiB
Python
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 RerankerConfig:
|
|
model_path: str
|
|
use_fp16: bool = True
|
|
|
|
@dataclass
|
|
class AppConfig:
|
|
logging: LoggingConfig
|
|
db_assistant: DBConfig
|
|
embedding: EmbeddingConfig
|
|
llm: LLMConfig
|
|
milvus: MilvusConfig
|
|
asr: ASRConfig
|
|
redis: RedisConfig
|
|
reranker: RerankerConfig
|
|
|
|
|
|
config_file = Path(__file__).parents[2] / 'conf' / 'app_config.yaml'
|
|
project_root = Path(__file__).parents[2]
|
|
context = OmegaConf.load(config_file)
|
|
schema = OmegaConf.structured(AppConfig)
|
|
app_config: AppConfig = OmegaConf.to_object(OmegaConf.merge(schema, context))
|
|
|
|
if not Path(app_config.reranker.model_path).is_absolute():
|
|
app_config.reranker.model_path = str(project_root / app_config.reranker.model_path)
|
|
|
|
if __name__ == '__main__':
|
|
print(app_config.db_assistant.host)
|