From 5ddf178b1a1403f53a1e323d4fd25372d18a6ba4 Mon Sep 17 00:00:00 2001 From: SlyAimer <2289782085@qq.com> Date: Fri, 17 Jan 2025 18:53:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=8E=86=E5=8F=B2=E6=96=87=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai_chat/ai_chat.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ai_chat/ai_chat.py b/src/ai_chat/ai_chat.py index ed9ebec..4bc1095 100644 --- a/src/ai_chat/ai_chat.py +++ b/src/ai_chat/ai_chat.py @@ -24,6 +24,8 @@ filename = os.getcwd() + '/src/ai_chat/chat_history.txt' def read_chat_history(): + with open(filename, 'w', encoding='utf-8'): + pass with open(filename, 'r', encoding='utf-8') as file: line_count = 1 for line in file: # 遍历文件中的每一行 @@ -41,8 +43,6 @@ def chat_history(line,content): 来源:https://api.v36.cm """ def v3_chat(content): - if not os.path.exists(filename): - os.makedirs(filename) line,txt = read_chat_history() lines = MaoYuNaSetting + "".join(txt) headers = {"Content-Type": "application/json", "Authorization": key} @@ -68,8 +68,6 @@ def v3_chat(content): 来源:https://api.deepseek.com """ def deepseek_chat(content): - if not os.path.exists(filename): - os.makedirs(filename) line,txt = read_chat_history() lines = MaoYuNaSetting + "".join(txt) From 6846b7372e7da474a536386f6997376a120c4f09 Mon Sep 17 00:00:00 2001 From: SlyAimer <2289782085@qq.com> Date: Fri, 17 Jan 2025 18:58:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=8E=86=E5=8F=B2=E6=96=87=E4=BB=B6bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai_chat/ai_chat.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ai_chat/ai_chat.py b/src/ai_chat/ai_chat.py index 4bc1095..56891e8 100644 --- a/src/ai_chat/ai_chat.py +++ b/src/ai_chat/ai_chat.py @@ -20,12 +20,18 @@ MaoYuNaSetting = character_settings.settings['MaoYuNa'][0] """回复历史文件""" filename = os.getcwd() + '/src/ai_chat/chat_history.txt' + +def check_file_exists(): + if os.path.exists(filename): + return True + else: + with open(filename, 'w', encoding='utf-8'): + pass + return False + # 读取历史记录 - - def read_chat_history(): - with open(filename, 'w', encoding='utf-8'): - pass + check_file_exists() with open(filename, 'r', encoding='utf-8') as file: line_count = 1 for line in file: # 遍历文件中的每一行