re-style: 格式化代码
This commit is contained in:
committed by
Windpicker-owo
parent
00ba07e0e1
commit
a79253c714
@@ -1,59 +1,58 @@
|
||||
import os
|
||||
import tomlkit
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
from datetime import datetime
|
||||
from tomlkit import TOMLDocument
|
||||
from tomlkit.items import Table, KeyType
|
||||
from rich.traceback import install
|
||||
from typing import List, Optional
|
||||
|
||||
import tomlkit
|
||||
from pydantic import Field
|
||||
from rich.traceback import install
|
||||
from tomlkit import TOMLDocument
|
||||
from tomlkit.items import KeyType, Table
|
||||
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config_base import ValidatedConfigBase
|
||||
from src.config.official_configs import (
|
||||
DatabaseConfig,
|
||||
AffinityFlowConfig,
|
||||
AntiPromptInjectionConfig,
|
||||
BotConfig,
|
||||
PersonalityConfig,
|
||||
ExpressionConfig,
|
||||
ChatConfig,
|
||||
EmojiConfig,
|
||||
MemoryConfig,
|
||||
MoodConfig,
|
||||
KeywordReactionConfig,
|
||||
ChineseTypoConfig,
|
||||
CommandConfig,
|
||||
CrossContextConfig,
|
||||
CustomPromptConfig,
|
||||
DatabaseConfig,
|
||||
DebugConfig,
|
||||
DependencyManagementConfig,
|
||||
EmojiConfig,
|
||||
ExperimentalConfig,
|
||||
ExpressionConfig,
|
||||
KeywordReactionConfig,
|
||||
LPMMKnowledgeConfig,
|
||||
MaimMessageConfig,
|
||||
MemoryConfig,
|
||||
MessageReceiveConfig,
|
||||
MoodConfig,
|
||||
NormalChatConfig,
|
||||
PermissionConfig,
|
||||
PersonalityConfig,
|
||||
PlanningSystemConfig,
|
||||
ProactiveThinkingConfig,
|
||||
RelationshipConfig,
|
||||
ResponsePostProcessConfig,
|
||||
ResponseSplitterConfig,
|
||||
ExperimentalConfig,
|
||||
MessageReceiveConfig,
|
||||
MaimMessageConfig,
|
||||
LPMMKnowledgeConfig,
|
||||
RelationshipConfig,
|
||||
ToolConfig,
|
||||
VoiceConfig,
|
||||
DebugConfig,
|
||||
CustomPromptConfig,
|
||||
VideoAnalysisConfig,
|
||||
DependencyManagementConfig,
|
||||
WebSearchConfig,
|
||||
AntiPromptInjectionConfig,
|
||||
SleepSystemConfig,
|
||||
CrossContextConfig,
|
||||
PermissionConfig,
|
||||
CommandConfig,
|
||||
PlanningSystemConfig,
|
||||
AffinityFlowConfig,
|
||||
ProactiveThinkingConfig,
|
||||
ToolConfig,
|
||||
VideoAnalysisConfig,
|
||||
VoiceConfig,
|
||||
WebSearchConfig,
|
||||
)
|
||||
|
||||
from .api_ada_configs import (
|
||||
ModelTaskConfig,
|
||||
ModelInfo,
|
||||
APIProvider,
|
||||
ModelInfo,
|
||||
ModelTaskConfig,
|
||||
)
|
||||
|
||||
|
||||
install(extra_lines=3)
|
||||
|
||||
|
||||
@@ -154,11 +153,11 @@ def compare_default_values(new, old, path=None, logs=None, changes=None):
|
||||
return logs, changes
|
||||
|
||||
|
||||
def _get_version_from_toml(toml_path) -> Optional[str]:
|
||||
def _get_version_from_toml(toml_path) -> str | None:
|
||||
"""从TOML文件中获取版本号"""
|
||||
if not os.path.exists(toml_path):
|
||||
return None
|
||||
with open(toml_path, "r", encoding="utf-8") as f:
|
||||
with open(toml_path, encoding="utf-8") as f:
|
||||
doc = tomlkit.load(f)
|
||||
if "inner" in doc and "version" in doc["inner"]: # type: ignore
|
||||
return doc["inner"]["version"] # type: ignore
|
||||
@@ -270,17 +269,17 @@ def _update_config_generic(config_name: str, template_name: str):
|
||||
|
||||
# 先读取 compare 下的模板(如果有),用于默认值变动检测
|
||||
if os.path.exists(compare_path):
|
||||
with open(compare_path, "r", encoding="utf-8") as f:
|
||||
with open(compare_path, encoding="utf-8") as f:
|
||||
compare_config = tomlkit.load(f)
|
||||
|
||||
# 读取当前模板
|
||||
with open(template_path, "r", encoding="utf-8") as f:
|
||||
with open(template_path, encoding="utf-8") as f:
|
||||
new_config = tomlkit.load(f)
|
||||
|
||||
# 检查默认值变化并处理(只有 compare_config 存在时才做)
|
||||
if compare_config:
|
||||
# 读取旧配置
|
||||
with open(old_config_path, "r", encoding="utf-8") as f:
|
||||
with open(old_config_path, encoding="utf-8") as f:
|
||||
old_config = tomlkit.load(f)
|
||||
logs, changes = compare_default_values(new_config, compare_config)
|
||||
if logs:
|
||||
@@ -318,7 +317,7 @@ def _update_config_generic(config_name: str, template_name: str):
|
||||
|
||||
# 读取旧配置文件和模板文件(如果前面没读过 old_config,这里再读一次)
|
||||
if old_config is None:
|
||||
with open(old_config_path, "r", encoding="utf-8") as f:
|
||||
with open(old_config_path, encoding="utf-8") as f:
|
||||
old_config = tomlkit.load(f)
|
||||
# new_config 已经读取
|
||||
|
||||
@@ -364,7 +363,7 @@ def _update_config_generic(config_name: str, template_name: str):
|
||||
|
||||
# 移除在新模板中已不存在的旧配置项
|
||||
logger.info(f"开始移除{config_name}中已废弃的配置项...")
|
||||
with open(template_path, "r", encoding="utf-8") as f:
|
||||
with open(template_path, encoding="utf-8") as f:
|
||||
template_doc = tomlkit.load(f)
|
||||
_remove_obsolete_keys(new_config, template_doc)
|
||||
logger.info(f"已移除{config_name}中已废弃的配置项")
|
||||
@@ -442,9 +441,9 @@ class Config(ValidatedConfigBase):
|
||||
class APIAdapterConfig(ValidatedConfigBase):
|
||||
"""API Adapter配置类"""
|
||||
|
||||
models: List[ModelInfo] = Field(..., min_items=1, description="模型列表")
|
||||
models: list[ModelInfo] = Field(..., min_items=1, description="模型列表")
|
||||
model_task_config: ModelTaskConfig = Field(..., description="模型任务配置")
|
||||
api_providers: List[APIProvider] = Field(..., min_items=1, description="API提供商列表")
|
||||
api_providers: list[APIProvider] = Field(..., min_items=1, description="API提供商列表")
|
||||
|
||||
def __init__(self, **data):
|
||||
super().__init__(**data)
|
||||
@@ -508,7 +507,7 @@ def load_config(config_path: str) -> Config:
|
||||
Config对象
|
||||
"""
|
||||
# 读取配置文件
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
config_data = tomlkit.load(f)
|
||||
|
||||
# 创建Config对象(各个配置类会自动进行 Pydantic 验证)
|
||||
@@ -531,7 +530,7 @@ def api_ada_load_config(config_path: str) -> APIAdapterConfig:
|
||||
APIAdapterConfig对象
|
||||
"""
|
||||
# 读取配置文件
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
with open(config_path, encoding="utf-8") as f:
|
||||
config_data = tomlkit.load(f)
|
||||
|
||||
config_dict = dict(config_data)
|
||||
|
||||
Reference in New Issue
Block a user