diff --git a/.gitignore b/.gitignore index 4e7c8dd..0a04256 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,6 @@ chat_bot.db-shm cloud_music_cookies.cookie chat_history.json /src/music/qrcode.png -/src/image/config/image.yaml -/src/ai_chat/config/chat_ai.yaml /chat.db /chat_bot.db-wal /chat_bot.db-shm @@ -19,3 +17,4 @@ bili.cookie *.log .mp4 /bili.cookie +/src/configs/api_config.py diff --git a/src/ai_chat/ai_chat.py b/src/ai_chat/ai_chat.py index 632b1c5..9561bbe 100644 --- a/src/ai_chat/ai_chat.py +++ b/src/ai_chat/ai_chat.py @@ -1,15 +1,7 @@ -import os import openai import requests -import yaml from src.my_sqlite.models.chat import GroupChatRole - -with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f: - chat = yaml.load(f.read(), Loader=yaml.FullLoader).get('chat_ai') - url = chat.get('v3url') - key = chat.get('v3key') - deepseek_url = chat.get('deepseek_url') - deepseek_key = chat.get('deepseek_key') +from src.configs.api_config import v3url, v3key, deepseek_url, deepseek_key openai.api_key = deepseek_key openai.base_url = deepseek_url @@ -21,7 +13,7 @@ async def v3_chat(group_openid,content): await GroupChatRole.save_chat_history(group_openid, {"role": "user", "content": content}) messages = await GroupChatRole.get_chat_history(group_openid) - headers = {"Content-Type": "application/json", "Authorization": key} + headers = {"Content-Type": "application/json", "Authorization": v3key} data = { "model": "gpt-3.5-turbo-0125", "messages": messages, @@ -29,7 +21,7 @@ async def v3_chat(group_openid,content): "temperature": 0.5, "stream": False } - response = requests.post(url, headers=headers, json=data) + response = requests.post(v3url, headers=headers, json=data) reply_content = response.json().get('choices')[0].get('message').get('content') await GroupChatRole.save_chat_history(group_openid, {"role": "assistant", "content": reply_content}) return reply_content @@ -39,6 +31,12 @@ async def v3_chat(group_openid,content): 来源:https://api.deepseek.com """ async def deepseek_chat(group_openid,content): + """ + ai 角色扮演聊天 + :param group_openid: + :param content: + :return: + """ await GroupChatRole.save_chat_history(group_openid, {"role": "user", "content": content}) messages = await GroupChatRole.get_chat_history(group_openid) diff --git a/src/ai_chat/config/example.chat_ai.yaml b/src/ai_chat/config/example.chat_ai.yaml deleted file mode 100644 index 77fe433..0000000 --- a/src/ai_chat/config/example.chat_ai.yaml +++ /dev/null @@ -1,6 +0,0 @@ -chat_ai: - admin_password: "" # 设置管理员认证密码 - v3url: "" - v3key: "" - deepseek_url: "" - deepseek_key: "" \ No newline at end of file diff --git a/src/configs/api_config_example.py b/src/configs/api_config_example.py new file mode 100644 index 0000000..51420f0 --- /dev/null +++ b/src/configs/api_config_example.py @@ -0,0 +1,26 @@ + +app_id="" +bot_account= "" + +""" +图床配置 +""" + +# SMMS图床相关配置 +smms_token= "" # sm.ms图床的token +smms_image_upload_history= "https=//sm.ms/api/v2/upload_history" # sm.ms图床获取上传图片历史API地址 + +# 聚合图床相关配置 +ju_he_token= "" # 聚合图床的token +ju_he_image_list= "https=//api.superbed.cn/timeline" # 聚合图床获取上传图片历史API地址 + +""" +AI +""" +admin_password= "123456"#默认注册管理员密码 +# 图灵机器人相关配置 +v3url= "https=//api.vveai.com/v1/chat/completions" +v3key= "" +# DeepSeek相关配置 +deepseek_url= "https://api.deepseek.com" +deepseek_key= "" \ No newline at end of file diff --git a/src/image/config/example.image.yaml b/src/image/config/example.image.yaml deleted file mode 100644 index eab8814..0000000 --- a/src/image/config/example.image.yaml +++ /dev/null @@ -1,16 +0,0 @@ -image: - app_id: "" - bot_account: "" - #SMMS图床相关配置 - smms_token: "" # sm.ms图床的token - smms_image_upload_history: "https://sm.ms/api/v2/upload_history" # sm.ms图床获取上传图片历史API地址 - #聚合图床相关配置 - ju_he_token: "" # 聚合图床的token - ju_he_image_list: "https://api.superbed.cn/timeline" # 聚合图床获取上传图片历史API地址 - - - - - - - diff --git a/src/image/get_image.py b/src/image/get_image.py index ea50e81..f602cd7 100644 --- a/src/image/get_image.py +++ b/src/image/get_image.py @@ -1,22 +1,11 @@ import os -import yaml import random import requests from PIL import Image, ImageDraw,ImageFont + from src.configs.path_config import image_local_path,image_local_qq_image_path,rua_png +from src.configs.api_config import smms_token,smms_image_upload_history,ju_he_token,ju_he_image_list,app_id,bot_account -with open(os.getcwd() +'/src/image/config/image.yaml', 'r', encoding='utf-8') as f: - image = yaml.load(f.read(), Loader=yaml.FullLoader).get('image') - # image_local_path = image.get('image_local_path') - # image_local_qq_image_path = image.get('image_local_qq_image_path') - smms_token = image.get('smms_token') - smms_image_upload_history = image.get('smms_image_upload_history') - ju_he_token = image.get('ju_he_token') - ju_he_image_list = image.get('ju_he_image_list') - app_id = image.get('app_id') - bot_account = image.get('bot_account') - -# qq_image_save__path = os.getcwd()+'/'+image_local_qq_image_path """本地图片""" def get_image_names(): diff --git a/src/qq_plugins/chat.py b/src/qq_plugins/chat.py index 62b8673..140a6b5 100644 --- a/src/qq_plugins/chat.py +++ b/src/qq_plugins/chat.py @@ -1,19 +1,9 @@ import re -import os -import yaml from nonebot.rule import to_me from nonebot.plugin import on_command from nonebot.adapters.qq import MessageEvent from src.my_sqlite.models.chat import ChatRole, GroupChatRole - -with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f1: - chat = yaml.load(f1, Loader=yaml.FullLoader).get('chat_ai') - admin_password = chat.get('admin_password') - - - - - +from src.configs.api_config import admin_password t1 = on_command("管理员注册", rule=to_me(), priority=10, block=True) diff --git a/src/qq_plugins/check.py b/src/qq_plugins/check.py index 4e9ce1a..ffa611a 100644 --- a/src/qq_plugins/check.py +++ b/src/qq_plugins/check.py @@ -14,11 +14,6 @@ import platform import psutil import time -with open(os.getcwd() + '/src/ai_chat/config/chat_ai.yaml', 'r', encoding='utf-8') as f1: - chat = yaml.load(f1, Loader=yaml.FullLoader).get('chat_ai') - admin_password = chat.get('admin_password') - - menu = ['/今日运势','/今日塔罗','/图','/点歌','/摸摸头','/群老婆','/今日老婆', "/开启ai","/关闭ai","/角色列表","/添加人设", "/更新人设", "/删除人设", "/切换人设", "/管理员注册", '/待办', '/test','/天气','我喜欢你', "❤", "/待办查询", "/新建待办", "/删除待办" ,"/cf","/B站搜索", "/BV搜索", "/喜报", "/悲报", "/奶龙", "/repo", "/info", "/menu"]