mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 03:32:33 +08:00
fix: 修复processing记录bug
This commit is contained in:
parent
acf6110a85
commit
b39bc076c9
|
@ -85,6 +85,11 @@ class DatabaseManager:
|
||||||
update `sessions` set `status` = 'explicitly_closed' where `name` = '{}' and `create_timestamp` = {}
|
update `sessions` set `status` = 'explicitly_closed' where `name` = '{}' and `create_timestamp` = {}
|
||||||
""".format(session_name, create_timestamp))
|
""".format(session_name, create_timestamp))
|
||||||
|
|
||||||
|
def set_session_ongoing(self, session_name: str, create_timestamp: int):
|
||||||
|
self.cursor.execute("""
|
||||||
|
update `sessions` set `status` = 'on_going' where `name` = '{}' and `create_timestamp` = {}
|
||||||
|
""".format(session_name, create_timestamp))
|
||||||
|
|
||||||
# 记载还没过期的session数据
|
# 记载还没过期的session数据
|
||||||
def load_valid_sessions(self) -> dict:
|
def load_valid_sessions(self) -> dict:
|
||||||
# 从数据库中加载所有还没过期的session
|
# 从数据库中加载所有还没过期的session
|
||||||
|
@ -150,31 +155,31 @@ class DatabaseManager:
|
||||||
# 获取此session_name后一个session的数据
|
# 获取此session_name后一个session的数据
|
||||||
def next_session(self, session_name: str, cursor_timestamp: int):
|
def next_session(self, session_name: str, cursor_timestamp: int):
|
||||||
|
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
select `name`, `type`, `number`, `create_timestamp`, `last_interact_timestamp`, `prompt`, `status`
|
select `name`, `type`, `number`, `create_timestamp`, `last_interact_timestamp`, `prompt`, `status`
|
||||||
from `sessions` where `name` = '{}' and `last_interact_timestamp` > {} order by `last_interact_timestamp` asc
|
from `sessions` where `name` = '{}' and `last_interact_timestamp` > {} order by `last_interact_timestamp` asc
|
||||||
limit 1
|
limit 1
|
||||||
""".format(session_name, cursor_timestamp))
|
""".format(session_name, cursor_timestamp))
|
||||||
results = self.cursor.fetchall()
|
results = self.cursor.fetchall()
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
return None
|
return None
|
||||||
result = results[0]
|
result = results[0]
|
||||||
|
|
||||||
session_name = result[0]
|
session_name = result[0]
|
||||||
subject_type = result[1]
|
subject_type = result[1]
|
||||||
subject_number = result[2]
|
subject_number = result[2]
|
||||||
create_timestamp = result[3]
|
create_timestamp = result[3]
|
||||||
last_interact_timestamp = result[4]
|
last_interact_timestamp = result[4]
|
||||||
prompt = result[5]
|
prompt = result[5]
|
||||||
status = result[6]
|
status = result[6]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'subject_type': subject_type,
|
'subject_type': subject_type,
|
||||||
'subject_number': subject_number,
|
'subject_number': subject_number,
|
||||||
'create_timestamp': create_timestamp,
|
'create_timestamp': create_timestamp,
|
||||||
'last_interact_timestamp': last_interact_timestamp,
|
'last_interact_timestamp': last_interact_timestamp,
|
||||||
'prompt': prompt
|
'prompt': prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
def list_history(self, session_name: str, capacity: int, page: int):
|
def list_history(self, session_name: str, capacity: int, page: int):
|
||||||
self.cursor.execute("""
|
self.cursor.execute("""
|
||||||
|
@ -202,6 +207,7 @@ class DatabaseManager:
|
||||||
|
|
||||||
return sessions
|
return sessions
|
||||||
|
|
||||||
|
|
||||||
def get_inst() -> DatabaseManager:
|
def get_inst() -> DatabaseManager:
|
||||||
global inst
|
global inst
|
||||||
return inst
|
return inst
|
||||||
|
|
|
@ -56,6 +56,8 @@ class Session:
|
||||||
|
|
||||||
last_interact_timestamp = 0
|
last_interact_timestamp = 0
|
||||||
|
|
||||||
|
just_switched_to_exist_session = False
|
||||||
|
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.create_timestamp = int(time.time())
|
self.create_timestamp = int(time.time())
|
||||||
|
@ -82,6 +84,11 @@ class Session:
|
||||||
res_ans = '\n\n'.join(res_ans_spt)
|
res_ans = '\n\n'.join(res_ans_spt)
|
||||||
|
|
||||||
self.prompt += "{}".format(res_ans) + '\n'
|
self.prompt += "{}".format(res_ans) + '\n'
|
||||||
|
|
||||||
|
if self.just_switched_to_exist_session:
|
||||||
|
self.just_switched_to_exist_session = False
|
||||||
|
self.set_ongoing()
|
||||||
|
|
||||||
return res_ans
|
return res_ans
|
||||||
|
|
||||||
def persistence(self):
|
def persistence(self):
|
||||||
|
@ -106,6 +113,11 @@ class Session:
|
||||||
self.prompt = ''
|
self.prompt = ''
|
||||||
self.create_timestamp = int(time.time())
|
self.create_timestamp = int(time.time())
|
||||||
self.last_interact_timestamp = int(time.time())
|
self.last_interact_timestamp = int(time.time())
|
||||||
|
self.just_switched_to_exist_session = False
|
||||||
|
|
||||||
|
# 将本session的数据库状态设置为on_going
|
||||||
|
def set_ongoing(self):
|
||||||
|
pkg.database.manager.get_inst().set_session_ongoing(self.name, self.create_timestamp)
|
||||||
|
|
||||||
# 切换到上一个session
|
# 切换到上一个session
|
||||||
def last_session(self):
|
def last_session(self):
|
||||||
|
@ -118,6 +130,8 @@ class Session:
|
||||||
self.create_timestamp = last_one['create_timestamp']
|
self.create_timestamp = last_one['create_timestamp']
|
||||||
self.last_interact_timestamp = last_one['last_interact_timestamp']
|
self.last_interact_timestamp = last_one['last_interact_timestamp']
|
||||||
self.prompt = last_one['prompt']
|
self.prompt = last_one['prompt']
|
||||||
|
|
||||||
|
just_switched = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next_session(self):
|
def next_session(self):
|
||||||
|
@ -130,6 +144,8 @@ class Session:
|
||||||
self.create_timestamp = next_one['create_timestamp']
|
self.create_timestamp = next_one['create_timestamp']
|
||||||
self.last_interact_timestamp = next_one['last_interact_timestamp']
|
self.last_interact_timestamp = next_one['last_interact_timestamp']
|
||||||
self.prompt = next_one['prompt']
|
self.prompt = next_one['prompt']
|
||||||
|
|
||||||
|
just_switched = True
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def list_history(self, capacity: int = 10, page: int = 0):
|
def list_history(self, capacity: int = 10, page: int = 0):
|
||||||
|
|
|
@ -2,6 +2,7 @@ from mirai import At, GroupMessage, MessageEvent, Mirai, Plain, StrangerMessage,
|
||||||
import pkg.openai.session
|
import pkg.openai.session
|
||||||
from func_timeout import func_set_timeout, FunctionTimedOut
|
from func_timeout import func_set_timeout, FunctionTimedOut
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
help_text = """帮助信息:
|
help_text = """帮助信息:
|
||||||
!help - 显示帮助
|
!help - 显示帮助
|
||||||
|
@ -114,7 +115,7 @@ class QQBotManager:
|
||||||
if current != -1:
|
if current != -1:
|
||||||
reply += ",当前会话是 #{}\n".format(current)
|
reply += ",当前会话是 #{}\n".format(current)
|
||||||
else:
|
else:
|
||||||
reply += ",当前处于全新会话"
|
reply += ",当前处于全新会话或不在此页"
|
||||||
|
|
||||||
else: # 消息
|
else: # 消息
|
||||||
session = pkg.openai.session.get_session(session_name)
|
session = pkg.openai.session.get_session(session_name)
|
||||||
|
@ -126,6 +127,7 @@ class QQBotManager:
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
async def on_person_message(self, event: MessageEvent):
|
async def on_person_message(self, event: MessageEvent):
|
||||||
|
global processing
|
||||||
if "person_{}".format(event.sender.id) in processing:
|
if "person_{}".format(event.sender.id) in processing:
|
||||||
return await self.bot.send(event, "err:正在处理中,请稍后再试")
|
return await self.bot.send(event, "err:正在处理中,请稍后再试")
|
||||||
|
|
||||||
|
@ -158,6 +160,7 @@ class QQBotManager:
|
||||||
return await self.bot.send(event, reply)
|
return await self.bot.send(event, reply)
|
||||||
|
|
||||||
async def on_group_message(self, event: GroupMessage):
|
async def on_group_message(self, event: GroupMessage):
|
||||||
|
global processing
|
||||||
if "group_{}".format(event.group.id) in processing:
|
if "group_{}".format(event.group.id) in processing:
|
||||||
return await self.bot.send(event, "err:正在处理中,请稍后再试")
|
return await self.bot.send(event, "err:正在处理中,请稍后再试")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user