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