正式添加aliyun平台,并修复一些bug,优化了日志系统

This commit is contained in:
2025-09-27 14:11:27 +08:00
parent 4d9e1bf355
commit 2ea4ed9acd
9 changed files with 25 additions and 18 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ napcat/
.venv
data/
logs/
uuid.db

View File

@@ -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 此项一般不需用修改

View File

@@ -1,4 +1,4 @@
import logging
from model.logger import setup_logger
import toml

View File

@@ -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):

View File

@@ -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":

View File

@@ -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

View File

@@ -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泄露风险。

View File

@@ -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

View File

@@ -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: