feat: 添加系统基本信息接口,包含操作系统、Python版本、CPU和内存使用情况
This commit is contained in:
@@ -10,7 +10,7 @@ ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
class APIBotConfig:
|
||||
"""机器人配置类"""
|
||||
|
||||
INNER_VERSION: Version # 配置文件内部版本号
|
||||
INNER_VERSION: str # 配置文件内部版本号(toml为字符串)
|
||||
MAI_VERSION: str # 硬编码的版本信息
|
||||
|
||||
# bot
|
||||
@@ -34,28 +34,28 @@ class APIBotConfig:
|
||||
appearance: str # 外貌特征描述
|
||||
|
||||
# schedule
|
||||
ENABLE_SCHEDULE_GEN: bool # 是否启用日程生成
|
||||
ENABLE_SCHEDULE_INTERACTION: bool # 是否启用日程交互
|
||||
PROMPT_SCHEDULE_GEN: str # 日程生成提示词
|
||||
SCHEDULE_DOING_UPDATE_INTERVAL: int # 日程进行中更新间隔
|
||||
SCHEDULE_TEMPERATURE: float # 日程生成温度
|
||||
TIME_ZONE: str # 时区
|
||||
enable_schedule_gen: bool # 是否启用日程表
|
||||
enable_schedule_interaction: bool # 日程表是否影响回复模式
|
||||
prompt_schedule_gen: str # 日程生成提示词
|
||||
schedule_doing_update_interval: int # 日程表更新间隔(秒)
|
||||
schedule_temperature: float # 日程表温度
|
||||
time_zone: str # 时区
|
||||
|
||||
# platforms
|
||||
platforms: Dict[str, str] # 平台信息
|
||||
|
||||
# chat
|
||||
allow_focus_mode: bool # 是否允许专注模式
|
||||
base_normal_chat_num: int # 基础普通聊天次数
|
||||
base_focused_chat_num: int # 基础专注聊天次数
|
||||
observation_context_size: int # 观察上下文大小
|
||||
allow_focus_mode: bool # 是否允许专注聊天状态
|
||||
base_normal_chat_num: int # 最多允许多少个群进行普通聊天
|
||||
base_focused_chat_num: int # 最多允许多少个群进行专注聊天
|
||||
observation_context_size: int # 观察到的最长上下文大小
|
||||
message_buffer: bool # 是否启用消息缓冲
|
||||
ban_words: List[str] # 禁止词列表
|
||||
ban_msgs_regex: List[str] # 禁止消息的正则表达式列表
|
||||
|
||||
# normal_chat
|
||||
MODEL_R1_PROBABILITY: float # 模型推理概率
|
||||
MODEL_V3_PROBABILITY: float # 模型普通概率
|
||||
model_reasoning_probability: float # 推理模型概率
|
||||
model_normal_probability: float # 普通模型概率
|
||||
emoji_chance: float # 表情符号出现概率
|
||||
thinking_timeout: int # 思考超时时间
|
||||
willing_mode: str # 意愿模式
|
||||
@@ -63,8 +63,8 @@ class APIBotConfig:
|
||||
response_interested_rate_amplifier: float # 回复兴趣率放大器
|
||||
down_frequency_rate: float # 降低频率率
|
||||
emoji_response_penalty: float # 表情回复惩罚
|
||||
mentioned_bot_inevitable_reply: bool # 提到机器人时是否必定回复
|
||||
at_bot_inevitable_reply: bool # @机器人时是否必定回复
|
||||
mentioned_bot_inevitable_reply: bool # 提及 bot 必然回复
|
||||
at_bot_inevitable_reply: bool # @bot 必然回复
|
||||
|
||||
# focus_chat
|
||||
reply_trigger_threshold: float # 回复触发阈值
|
||||
@@ -78,24 +78,25 @@ class APIBotConfig:
|
||||
# emoji
|
||||
max_emoji_num: int # 最大表情符号数量
|
||||
max_reach_deletion: bool # 达到最大数量时是否删除
|
||||
EMOJI_CHECK_INTERVAL: int # 表情检查间隔
|
||||
EMOJI_REGISTER_INTERVAL: Optional[int] # 表情注册间隔(兼容性保留)
|
||||
EMOJI_SAVE: bool # 是否保存表情
|
||||
EMOJI_CHECK: bool # 是否检查表情
|
||||
EMOJI_CHECK_PROMPT: str # 表情检查提示词
|
||||
check_interval: int # 检查表情包的时间间隔(分钟)
|
||||
save_pic: bool # 是否保存图片
|
||||
save_emoji: bool # 是否保存表情包
|
||||
steal_emoji: bool # 是否偷取表情包
|
||||
enable_check: bool # 是否启用表情包过滤
|
||||
check_prompt: str # 表情包过滤要求
|
||||
|
||||
# memory
|
||||
build_memory_interval: int # 构建记忆间隔
|
||||
memory_build_distribution: List[float] # 记忆构建分布
|
||||
build_memory_sample_num: int # 构建记忆样本数量
|
||||
build_memory_sample_length: int # 构建记忆样本长度
|
||||
build_memory_interval: int # 记忆构建间隔
|
||||
build_memory_distribution: List[float] # 记忆构建分布
|
||||
build_memory_sample_num: int # 采样数量
|
||||
build_memory_sample_length: int # 采样长度
|
||||
memory_compress_rate: float # 记忆压缩率
|
||||
forget_memory_interval: int # 忘记记忆间隔
|
||||
memory_forget_time: int # 记忆忘记时间
|
||||
memory_forget_percentage: float # 记忆忘记百分比
|
||||
consolidate_memory_interval: int # 巩固记忆间隔
|
||||
consolidation_similarity_threshold: float # 巩固相似度阈值
|
||||
consolidation_check_percentage: float # 巩固检查百分比
|
||||
forget_memory_interval: int # 记忆遗忘间隔
|
||||
memory_forget_time: int # 记忆遗忘时间(小时)
|
||||
memory_forget_percentage: float # 记忆遗忘比例
|
||||
consolidate_memory_interval: int # 记忆整合间隔
|
||||
consolidation_similarity_threshold: float # 相似度阈值
|
||||
consolidation_check_percentage: float # 检查节点比例
|
||||
memory_ban_words: List[str] # 记忆禁止词列表
|
||||
|
||||
# mood
|
||||
@@ -128,21 +129,19 @@ class APIBotConfig:
|
||||
# experimental
|
||||
enable_friend_chat: bool # 是否启用好友聊天
|
||||
talk_allowed_private: List[int] # 允许私聊的QQ号列表
|
||||
enable_pfc_chatting: bool # 是否启用PFC聊天
|
||||
pfc_chatting: bool # 是否启用PFC聊天
|
||||
|
||||
# 模型配置
|
||||
llm_reasoning: Dict[str, Any] # 推理模型配置
|
||||
llm_normal: Dict[str, Any] # 普通模型配置
|
||||
llm_topic_judge: Dict[str, Any] # 主题判断模型配置
|
||||
llm_summary: Dict[str, Any] # 总结模型配置
|
||||
llm_emotion_judge: Optional[Dict[str, Any]] # 情绪判断模型配置(兼容性保留)
|
||||
embedding: Dict[str, Any] # 嵌入模型配置
|
||||
vlm: Dict[str, Any] # VLM模型配置
|
||||
moderation: Optional[Dict[str, Any]] # 审核模型配置(兼容性保留)
|
||||
llm_heartflow: Dict[str, Any] # 心流模型配置
|
||||
llm_observation: Dict[str, Any] # 观察模型配置
|
||||
llm_sub_heartflow: Dict[str, Any] # 子心流模型配置
|
||||
llm_heartflow: Dict[str, Any] # 心流模型配置
|
||||
llm_plan: Optional[Dict[str, Any]] # 计划模型配置
|
||||
embedding: Dict[str, Any] # 嵌入模型配置
|
||||
llm_PFC_action_planner: Optional[Dict[str, Any]] # PFC行动计划模型配置
|
||||
llm_PFC_chat: Optional[Dict[str, Any]] # PFC聊天模型配置
|
||||
llm_PFC_reply_checker: Optional[Dict[str, Any]] # PFC回复检查模型配置
|
||||
@@ -150,6 +149,63 @@ class APIBotConfig:
|
||||
|
||||
api_urls: Optional[Dict[str, str]] # API地址配置
|
||||
|
||||
@staticmethod
|
||||
def validate_config(config: dict):
|
||||
"""
|
||||
校验传入的 toml 配置字典是否合法。
|
||||
:param config: toml库load后的配置字典
|
||||
:raises: ValueError, KeyError, TypeError
|
||||
"""
|
||||
# 检查主层级
|
||||
required_sections = [
|
||||
"inner", "bot", "groups", "personality", "identity", "schedule",
|
||||
"platforms", "chat", "normal_chat", "focus_chat", "emoji", "memory",
|
||||
"mood", "keywords_reaction", "chinese_typo", "response_splitter",
|
||||
"remote", "experimental", "model"
|
||||
]
|
||||
for section in required_sections:
|
||||
if section not in config:
|
||||
raise KeyError(f"缺少配置段: [{section}]")
|
||||
|
||||
# 检查部分关键字段
|
||||
if "version" not in config["inner"]:
|
||||
raise KeyError("缺少 inner.version 字段")
|
||||
if not isinstance(config["inner"]["version"], str):
|
||||
raise TypeError("inner.version 必须为字符串")
|
||||
|
||||
if "qq" not in config["bot"]:
|
||||
raise KeyError("缺少 bot.qq 字段")
|
||||
if not isinstance(config["bot"]["qq"], int):
|
||||
raise TypeError("bot.qq 必须为整数")
|
||||
|
||||
if "personality_core" not in config["personality"]:
|
||||
raise KeyError("缺少 personality.personality_core 字段")
|
||||
if not isinstance(config["personality"]["personality_core"], str):
|
||||
raise TypeError("personality.personality_core 必须为字符串")
|
||||
|
||||
if "identity_detail" not in config["identity"]:
|
||||
raise KeyError("缺少 identity.identity_detail 字段")
|
||||
if not isinstance(config["identity"]["identity_detail"], list):
|
||||
raise TypeError("identity.identity_detail 必须为列表")
|
||||
|
||||
# 可继续添加更多字段的类型和值检查
|
||||
# ...
|
||||
|
||||
# 检查模型配置
|
||||
model_keys = [
|
||||
"llm_reasoning", "llm_normal", "llm_topic_judge", "llm_summary",
|
||||
"vlm", "llm_heartflow", "llm_observation", "llm_sub_heartflow",
|
||||
"embedding"
|
||||
]
|
||||
if "model" not in config:
|
||||
raise KeyError("缺少 [model] 配置段")
|
||||
for key in model_keys:
|
||||
if key not in config["model"]:
|
||||
raise KeyError(f"缺少 model.{key} 配置")
|
||||
|
||||
# 检查通过
|
||||
return True
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class APIEnvConfig:
|
||||
@@ -182,6 +238,56 @@ class APIEnvConfig:
|
||||
def get_env(self) -> str:
|
||||
return "env"
|
||||
|
||||
@staticmethod
|
||||
def validate_config(config: dict):
|
||||
"""
|
||||
校验环境变量配置字典是否合法。
|
||||
:param config: 环境变量配置字典
|
||||
:raises: KeyError, TypeError
|
||||
"""
|
||||
required_fields = [
|
||||
"HOST", "PORT", "PLUGINS", "MONGODB_HOST", "MONGODB_PORT", "DATABASE_NAME",
|
||||
"CHAT_ANY_WHERE_BASE_URL", "SILICONFLOW_BASE_URL", "DEEP_SEEK_BASE_URL"
|
||||
]
|
||||
for field in required_fields:
|
||||
if field not in config:
|
||||
raise KeyError(f"缺少环境变量配置字段: {field}")
|
||||
|
||||
if not isinstance(config["HOST"], str):
|
||||
raise TypeError("HOST 必须为字符串")
|
||||
if not isinstance(config["PORT"], int):
|
||||
raise TypeError("PORT 必须为整数")
|
||||
if not isinstance(config["PLUGINS"], list):
|
||||
raise TypeError("PLUGINS 必须为列表")
|
||||
if not isinstance(config["MONGODB_HOST"], str):
|
||||
raise TypeError("MONGODB_HOST 必须为字符串")
|
||||
if not isinstance(config["MONGODB_PORT"], int):
|
||||
raise TypeError("MONGODB_PORT 必须为整数")
|
||||
if not isinstance(config["DATABASE_NAME"], str):
|
||||
raise TypeError("DATABASE_NAME 必须为字符串")
|
||||
if not isinstance(config["CHAT_ANY_WHERE_BASE_URL"], str):
|
||||
raise TypeError("CHAT_ANY_WHERE_BASE_URL 必须为字符串")
|
||||
if not isinstance(config["SILICONFLOW_BASE_URL"], str):
|
||||
raise TypeError("SILICONFLOW_BASE_URL 必须为字符串")
|
||||
if not isinstance(config["DEEP_SEEK_BASE_URL"], str):
|
||||
raise TypeError("DEEP_SEEK_BASE_URL 必须为字符串")
|
||||
|
||||
# 可选字段类型检查
|
||||
optional_str_fields = [
|
||||
"DEEP_SEEK_KEY", "CHAT_ANY_WHERE_KEY", "SILICONFLOW_KEY",
|
||||
"CONSOLE_LOG_LEVEL", "FILE_LOG_LEVEL",
|
||||
"DEFAULT_CONSOLE_LOG_LEVEL", "DEFAULT_FILE_LOG_LEVEL"
|
||||
]
|
||||
for field in optional_str_fields:
|
||||
if field in config and config[field] is not None and not isinstance(config[field], str):
|
||||
raise TypeError(f"{field} 必须为字符串或None")
|
||||
|
||||
if "SIMPLE_OUTPUT" in config and config["SIMPLE_OUTPUT"] is not None and not isinstance(config["SIMPLE_OUTPUT"], bool):
|
||||
raise TypeError("SIMPLE_OUTPUT 必须为布尔值或None")
|
||||
|
||||
# 检查通过
|
||||
return True
|
||||
|
||||
|
||||
print("当前路径:")
|
||||
print(ROOT_PATH)
|
||||
|
||||
Reference in New Issue
Block a user