From 655cd488456d106afe33fde1b6f7255583cae99d Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Sun, 11 Dec 2022 10:17:46 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E7=BC=BA?= =?UTF-8?q?=E5=B0=91db=5Finst=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/qqbot/core.py | 22 ++++++++++++++++++---- main.py | 7 ++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cores/qqbot/core.py b/cores/qqbot/core.py index 775593591..6ab5b013e 100644 --- a/cores/qqbot/core.py +++ b/cores/qqbot/core.py @@ -9,7 +9,7 @@ from botpy.message import DirectMessage import json chatgpt = "" -db = "" +# db = "" session_dict = {} max_tokens = 2000 @@ -21,11 +21,11 @@ class botClient(botpy.Client): print(message.content) await oper_msg(message=message, at=False) -def initBot(chatgpt_inst, db_inst): +def initBot(chatgpt_inst): global chatgpt chatgpt = chatgpt_inst - global db - db = db_inst + # global db + # db = db_inst global max_tokens max_tokens = int(chatgpt_inst.getConfigs()['total_tokens_limit']) with open("./configs/config.yaml", 'r', encoding='utf-8') as ymlfile: @@ -158,6 +158,20 @@ async def oper_msg(message, at=False): # print(single_record) cache_data_list.append(single_record) + # 写入数据库 + # try: + # data = { + # "data": cache_data_list + # } + # data_str = json.dumps(data) + # if len(cache_data_list) > 1: + # db.update_session(session_id, data_str) + # else: + # db.insert_session(session_id, data_str) + # except Exception as e: + # print(e) + # print("数据库写入失败") + session_dict[session_id] = cache_data_list # #检测是否存在url,如果存在,则去除url 防止被qq频道过滤 diff --git a/main.py b/main.py index 3f4c0ce8d..6a2890321 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import cores.qqbot.core as qqBot from cores.openai.core import ChatGPT import asyncio import yaml - +from cores.database.conn import dbConn def main(): # 读取参数 # with open('configs/config.yaml', 'r', encoding='utf-8') as f: @@ -11,8 +11,9 @@ def main(): # print(chatGPT_configs) #实例化ChatGPT chatgpt = ChatGPT() - #执行qqBot + # db = dbConn() + # #执行qqBot + # qqBot.initBot(chatgpt, db) qqBot.initBot(chatgpt) - if __name__ == "__main__": main() \ No newline at end of file