feat: 增加平台支持的url配置
This commit is contained in:
@@ -133,7 +133,7 @@ class ChatBot:
|
||||
|
||||
response = None
|
||||
# 开始组织语言
|
||||
if random() < reply_probability + 100:
|
||||
if random() < reply_probability:
|
||||
bot_user_info = UserInfo(
|
||||
user_id=global_config.BOT_QQ,
|
||||
user_nickname=global_config.BOT_NICKNAME,
|
||||
|
||||
@@ -108,12 +108,14 @@ class BotConfig:
|
||||
build_memory_sample_num: int = 10 # 记忆构建采样数量
|
||||
build_memory_sample_length: int = 20 # 记忆构建采样长度
|
||||
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均值,标准差,权重
|
||||
memory_ban_words: list = field(
|
||||
default_factory=lambda: ["表情包", "图片", "回复", "聊天记录"]
|
||||
) # 添加新的配置项默认值
|
||||
|
||||
api_urls: Dict[str, str] = field(default_factory=lambda: {})
|
||||
|
||||
@staticmethod
|
||||
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)
|
||||
if config.INNER_VERSION in SpecifierSet(">=0.0.11"):
|
||||
config.memory_build_distribution = memory_config.get(
|
||||
"memory_build_distribution",
|
||||
config.memory_build_distribution
|
||||
"memory_build_distribution", config.memory_build_distribution
|
||||
)
|
||||
config.build_memory_sample_num = memory_config.get(
|
||||
"build_memory_sample_num",
|
||||
config.build_memory_sample_num
|
||||
"build_memory_sample_num", config.build_memory_sample_num
|
||||
)
|
||||
config.build_memory_sample_length = memory_config.get(
|
||||
"build_memory_sample_length",
|
||||
config.build_memory_sample_length
|
||||
"build_memory_sample_length", config.build_memory_sample_length
|
||||
)
|
||||
|
||||
|
||||
def remote(parent: dict):
|
||||
remote_config = parent["remote"]
|
||||
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.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):
|
||||
others_config = parent["others"]
|
||||
# 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},
|
||||
"chinese_typo": {"func": chinese_typo, "support": ">=0.0.3", "necessary": False},
|
||||
"groups": {"func": groups, "support": ">=0.0.0"},
|
||||
"platforms": {"func": platforms, "support": ">=0.0.11"},
|
||||
"others": {"func": others, "support": ">=0.0.0"},
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,11 @@ class Message_Sender:
|
||||
|
||||
message_preview = truncate_message(message.processed_plain_text)
|
||||
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}”成功")
|
||||
except Exception as e:
|
||||
logger.error(f"发送消息“{message_preview}”失败: {str(e)}")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "0.0.11"
|
||||
version = "0.0.12"
|
||||
|
||||
#以下是给开发人员阅读的,一般用户不需要阅读
|
||||
#如果你想要修改配置文件,请在修改后将version的值进行变更
|
||||
@@ -29,6 +29,10 @@ personality_2_probability = 0.2 # 第二种人格出现概率
|
||||
personality_3_probability = 0.1 # 第三种人格出现概率,请确保三个概率相加等于1
|
||||
prompt_schedule = "用一句话或几句话描述描述性格特点和其他特征"
|
||||
|
||||
[platforms] # 必填项目,填写每个平台适配器提供的链接
|
||||
qq="http://127.0.0.1:18002/api/message"
|
||||
|
||||
|
||||
[message]
|
||||
min_text_length = 2 # 与麦麦聊天时麦麦只会回答文本大于等于此数的消息
|
||||
max_context_size = 15 # 麦麦获得的上文数量
|
||||
|
||||
Reference in New Issue
Block a user