diff --git a/.gitignore b/.gitignore index d22ea15..68921e0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ napcat/ .venv data/ logs/ +uuid.db \ No newline at end of file diff --git a/config.toml b/config.toml index 5e1e483..cae5c1e 100644 --- a/config.toml +++ b/config.toml @@ -11,7 +11,7 @@ remote_mode = false # 是否远程模式, 即 NapCat 服务不在本机运行 ps # 功能配置 allowed_groups = "all" # 授权群聊,all为全部,eg:[123456789, 987654321] allowed_users = "all" # 授权用户,all为全部,eg:[123456789, 987654321] -ai_service = "xyit" # ai平台 支持 “dify” “xyit" +ai_service = "xyit" # ai平台 支持 "dify" "mcunc" "xyit" "aliyun" friend_auto = false # 好友自动同意 group_auto = true group_welcome = false # 入群欢迎 @@ -46,10 +46,10 @@ dify_ip= "" # https://ip:port dify_token = "" # token # mcunc配置 ai_service选择mcunc时需配置 -xyit_ip = "https://ai.openapi.mcunc.cn" # ip 此项一般不需用修改 -xyit_appID = "" # appID -xyit_appKEY = "" # appKEY -xyit_model = "maoniang" # 模型名称 +mcunc_ip = "https://ai.openapi.mcunc.cn" # ip 此项一般不需用修改 +mcunc_appID = "" # appID +mcunc_appKEY = "" # appKEY +mcunc_model = "maoniang" # 模型名称名称 # xyit配置 ai_service选择xyit时需配置 xyit_ip = "https://ai.openapi.xyit.net" # ip 此项一般不需用修改 diff --git a/control/request.py b/control/request.py index 5ce2124..9dfa6c5 100644 --- a/control/request.py +++ b/control/request.py @@ -1,4 +1,4 @@ -import logging +from model.logger import setup_logger import toml diff --git a/main.py b/main.py index 47cab8c..fa85a0f 100644 --- a/main.py +++ b/main.py @@ -15,14 +15,14 @@ with open("./config.toml", "r", encoding="utf-8") as f: bt_uin = config.get("bot_qq") root = config.get("root_qq") ws_uri = config.get("ws_uri") - web_uri = config.get("web_uri") + webui_uri = config.get("webui_uri") webui_token = config.get("webui_token") ws_token = config.get("ws_token") ws_listen_ip = config.get("ws_listen_ip") remote_mode = config.get("remote_mode") bot = BotClient() -api = bot.run_blocking(bt_uin=bt_uin, root=root, ws_uri=ws_uri, web_uri=web_uri, webui_token=webui_token, ws_token=ws_token, ws_listen_ip=ws_listen_ip, remote_mode=remote_mode) +api = bot.run_blocking(bt_uin=bt_uin, root=root, ws_uri=ws_uri, webui_uri=webui_uri, webui_token=webui_token, ws_token=ws_token, ws_listen_ip=ws_listen_ip, remote_mode=remote_mode) @bot.group_event() async def on_group_message(msg): diff --git a/model/Clear.py b/model/Clear.py index 0fc66b5..91436bf 100644 --- a/model/Clear.py +++ b/model/Clear.py @@ -20,9 +20,9 @@ class Clear: clean_nopermissoin_message = config.get("clean_nopermissoin_message") if "{group_id}" in clean_one_success_message: - clean_one_success_message.replace("{group_id}", self.group_id) + clean_one_success_message = clean_one_success_message.replace("{group_id}", self.group_id) if "{group_id}" in clean_one_notfound_message: - clean_one_notfound_message.replace("{group_id}", self.group_id) + clean_one_notfound_message = clean_one_notfound_message.replace("{group_id}", self.group_id) if self.is_root(): if self.group_id == "all": diff --git a/model/ai_model.py b/model/ai_model.py index 7df198a..9c79fd7 100644 --- a/model/ai_model.py +++ b/model/ai_model.py @@ -27,6 +27,9 @@ def main(message,qid,group_openid): elif ai_service == "xyit": from model.ai_models import xyit return xyit.main(message, group_openid) + elif ai_service == "aliyun": + from model.ai_models import aliyun + return aliyun.main(message, group_openid) else: logger.error("未配置ai_service") return error_message diff --git a/model/ai_models/aliyun.py b/model/ai_models/aliyun.py index e6c989d..db9b198 100644 --- a/model/ai_models/aliyun.py +++ b/model/ai_models/aliyun.py @@ -26,6 +26,8 @@ def main(message, group_openid): else: logger.info(f"找到 UUID: {uuid}") + logger.info("请求平台:aliyun") + # 发送请求 response = Application.call( # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 diff --git a/model/ai_models/dify.py b/model/ai_models/dify.py index aba1d0b..24550de 100644 --- a/model/ai_models/dify.py +++ b/model/ai_models/dify.py @@ -22,9 +22,9 @@ def main(message, group_openid): uuid = get_uuid(group_openid) if uuid == "": - logging.info("未找到 UUID") + logger.info("未找到 UUID") else: - logging.info(f"找到 UUID: {uuid}") + logger.info(f"找到 UUID: {uuid}") url = f"{dify_ip}/v1/chat-messages" # 替换为实际的 API 地址 @@ -45,7 +45,7 @@ def main(message, group_openid): "auto_generate_name": True # (选填)自动生成标题,默认为 True } - logging.info("请求平台:dify") + logger.info("请求平台:dify") # 发送 POST 请求 @@ -54,7 +54,7 @@ def main(message, group_openid): # 检查响应状态码 if response.status_code == 200: - logging.info("请求成功!返回结果:") + logger.info("请求成功!返回结果:") response_data = response.json() print(response_data) # test # 存储uuid @@ -66,12 +66,12 @@ def main(message, group_openid): answer = response_data.get("answer", error_message) return answer else: - logging.info(f"请求失败!状态码: {response.status_code}") - logging.info(f"错误信息: {response.text}") # 打印错误信息 + logger.info(f"请求失败!状态码: {response.status_code}") + logger.info(f"错误信息: {response.text}") # 打印错误信息 return error_message except Exception as e: - logging.info(f"请求过程中出现异常: {e}") + logger.info(f"请求过程中出现异常: {e}") return error_message diff --git a/model/logger.py b/model/logger.py index cc9dd6a..3dc3ef6 100644 --- a/model/logger.py +++ b/model/logger.py @@ -17,8 +17,9 @@ def setup_logger(log_file=None, log_level=logging.INFO, max_bytes=10485760, back logging.Logger: 配置好的日志记录器 """ # 创建logger - logger = logging.getLogger('mcsmapi') + logger = logging.getLogger('chatbot-napcat') logger.setLevel(log_level) + logger.propagate = False # 避免重复添加handler if logger.handlers: