- 4维指纹采集: 性能/语言/能力/行为 - models.py 已加入 IdentityFingerprintModel (第5维数据模型) - comparator.py 已升级为5维评分 (含identity维度比较) - reporter.py 已加入身份验证报告输出 - main.py 已集成identity采集流程 - identity collector 待下次提交补充完整代码
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""YAML configuration loader and validator."""
|
|
|
|
import yaml
|
|
from pathlib import Path
|
|
from .models import ChannelConfig, CollectionConfig
|
|
|
|
|
|
def load_config(config_path: str) -> dict:
|
|
"""Load and validate configuration from YAML file."""
|
|
path = Path(config_path)
|
|
if not path.exists():
|
|
raise FileNotFoundError(f"Config file not found: {config_path}")
|
|
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
raw = yaml.safe_load(f)
|
|
|
|
# Parse channel configs
|
|
genuine = _parse_channel(raw.get('genuine', {}), 'genuine')
|
|
suspect = _parse_channel(raw.get('suspect', {}), 'suspect')
|
|
|
|
# Parse collection config
|
|
coll = raw.get('collection', {})
|
|
collection = CollectionConfig(
|
|
repeat_count=coll.get('repeat_count', 3),
|
|
timeout=coll.get('timeout', 60),
|
|
max_tokens=coll.get('max_tokens', 1024),
|
|
anthropic_version=coll.get('anthropic_version', '2023-06-01'),
|
|
)
|
|
|
|
# Parse output config
|
|
output = raw.get('output', {})
|
|
|
|
return {
|
|
'genuine': genuine,
|
|
'suspect': suspect,
|
|
'collection': collection,
|
|
'output': output,
|
|
}
|
|
|
|
|
|
def _parse_channel(data: dict, name: str) -> ChannelConfig:
|
|
"""Parse and validate a channel configuration."""
|
|
required = ['base_url', 'api_key', 'model']
|
|
for key in required:
|
|
if key not in data or not data[key]:
|
|
raise ValueError(f"Channel '{name}' missing required field: {key}")
|
|
|
|
return ChannelConfig(
|
|
base_url=data['base_url'].rstrip('/'),
|
|
api_key=data['api_key'],
|
|
model=data['model'],
|
|
)
|