feat: 增加平台支持的url配置

This commit is contained in:
tcmofashi
2025-03-28 04:20:45 +08:00
parent 00436c9a96
commit c72e473934
4 changed files with 24 additions and 11 deletions

View File

@@ -133,7 +133,7 @@ class ChatBot:
response = None response = None
# 开始组织语言 # 开始组织语言
if random() < reply_probability + 100: if random() < reply_probability:
bot_user_info = UserInfo( bot_user_info = UserInfo(
user_id=global_config.BOT_QQ, user_id=global_config.BOT_QQ,
user_nickname=global_config.BOT_NICKNAME, user_nickname=global_config.BOT_NICKNAME,

View File

@@ -108,12 +108,14 @@ class BotConfig:
build_memory_sample_num: int = 10 # 记忆构建采样数量 build_memory_sample_num: int = 10 # 记忆构建采样数量
build_memory_sample_length: int = 20 # 记忆构建采样长度 build_memory_sample_length: int = 20 # 记忆构建采样长度
memory_build_distribution: list = field( memory_build_distribution: list = field(
default_factory=lambda: [4,2,0.6,24,8,0.4] default_factory=lambda: [4, 2, 0.6, 24, 8, 0.4]
) # 记忆构建分布参数分布1均值标准差权重分布2均值标准差权重 ) # 记忆构建分布参数分布1均值标准差权重分布2均值标准差权重
memory_ban_words: list = field( memory_ban_words: list = field(
default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"] default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"]
) # 添加新的配置项默认值 ) # 添加新的配置项默认值
api_urls: Dict[str, str] = field(default_factory=lambda: {})
@staticmethod @staticmethod
def get_config_dir() -> str: def get_config_dir() -> str:
"""获取配置文件目录""" """获取配置文件目录"""
@@ -320,19 +322,15 @@ class BotConfig:
config.memory_compress_rate = memory_config.get("memory_compress_rate", config.memory_compress_rate) config.memory_compress_rate = memory_config.get("memory_compress_rate", config.memory_compress_rate)
if config.INNER_VERSION in SpecifierSet(">=0.0.11"): if config.INNER_VERSION in SpecifierSet(">=0.0.11"):
config.memory_build_distribution = memory_config.get( config.memory_build_distribution = memory_config.get(
"memory_build_distribution", "memory_build_distribution", config.memory_build_distribution
config.memory_build_distribution
) )
config.build_memory_sample_num = memory_config.get( config.build_memory_sample_num = memory_config.get(
"build_memory_sample_num", "build_memory_sample_num", config.build_memory_sample_num
config.build_memory_sample_num
) )
config.build_memory_sample_length = memory_config.get( config.build_memory_sample_length = memory_config.get(
"build_memory_sample_length", "build_memory_sample_length", config.build_memory_sample_length
config.build_memory_sample_length
) )
def remote(parent: dict): def remote(parent: dict):
remote_config = parent["remote"] remote_config = parent["remote"]
config.remote_enable = remote_config.get("enable", config.remote_enable) config.remote_enable = remote_config.get("enable", config.remote_enable)
@@ -366,6 +364,12 @@ class BotConfig:
config.talk_frequency_down_groups = set(groups_config.get("talk_frequency_down", [])) config.talk_frequency_down_groups = set(groups_config.get("talk_frequency_down", []))
config.ban_user_id = set(groups_config.get("ban_user_id", [])) config.ban_user_id = set(groups_config.get("ban_user_id", []))
def platforms(parent: dict):
platforms_config = parent["platforms"]
if platforms_config and isinstance(platforms_config, dict):
for k in platforms_config.keys():
config.api_urls[k] = platforms_config[k]
def others(parent: dict): def others(parent: dict):
others_config = parent["others"] others_config = parent["others"]
# config.enable_advance_output = others_config.get("enable_advance_output", config.enable_advance_output) # config.enable_advance_output = others_config.get("enable_advance_output", config.enable_advance_output)
@@ -394,6 +398,7 @@ class BotConfig:
"keywords_reaction": {"func": keywords_reaction, "support": ">=0.0.2", "necessary": False}, "keywords_reaction": {"func": keywords_reaction, "support": ">=0.0.2", "necessary": False},
"chinese_typo": {"func": chinese_typo, "support": ">=0.0.3", "necessary": False}, "chinese_typo": {"func": chinese_typo, "support": ">=0.0.3", "necessary": False},
"groups": {"func": groups, "support": ">=0.0.0"}, "groups": {"func": groups, "support": ">=0.0.0"},
"platforms": {"func": platforms, "support": ">=0.0.11"},
"others": {"func": others, "support": ">=0.0.0"}, "others": {"func": others, "support": ">=0.0.0"},
} }

View File

@@ -62,7 +62,11 @@ class Message_Sender:
message_preview = truncate_message(message.processed_plain_text) message_preview = truncate_message(message.processed_plain_text)
try: try:
result = await global_api.send_message("http://127.0.0.1:18002/api/message", message_json) end_point = global_config.api_urls.get(message.message_info.platform, None)
if end_point:
result = await global_api.send_message(end_point, message_json)
else:
raise ValueError(f"未找到平台:{message.message_info.platform} 的url配置请检查配置文件")
logger.success(f"发送消息“{message_preview}”成功") logger.success(f"发送消息“{message_preview}”成功")
except Exception as e: except Exception as e:
logger.error(f"发送消息“{message_preview}”失败: {str(e)}") logger.error(f"发送消息“{message_preview}”失败: {str(e)}")

View File

@@ -1,5 +1,5 @@
[inner] [inner]
version = "0.0.11" version = "0.0.12"
#以下是给开发人员阅读的,一般用户不需要阅读 #以下是给开发人员阅读的,一般用户不需要阅读
#如果你想要修改配置文件请在修改后将version的值进行变更 #如果你想要修改配置文件请在修改后将version的值进行变更
@@ -29,6 +29,10 @@ personality_2_probability = 0.2 # 第二种人格出现概率
personality_3_probability = 0.1 # 第三种人格出现概率请确保三个概率相加等于1 personality_3_probability = 0.1 # 第三种人格出现概率请确保三个概率相加等于1
prompt_schedule = "用一句话或几句话描述描述性格特点和其他特征" prompt_schedule = "用一句话或几句话描述描述性格特点和其他特征"
[platforms] # 必填项目,填写每个平台适配器提供的链接
qq="http://127.0.0.1:18002/api/message"
[message] [message]
min_text_length = 2 # 与麦麦聊天时麦麦只会回答文本大于等于此数的消息 min_text_length = 2 # 与麦麦聊天时麦麦只会回答文本大于等于此数的消息
max_context_size = 15 # 麦麦获得的上文数量 max_context_size = 15 # 麦麦获得的上文数量