mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 支持!resend指令重新回复上一个问题 (#87)
This commit is contained in:
parent
97ddb10ff5
commit
2d62b5937e
|
@ -179,6 +179,18 @@ class Session:
|
|||
|
||||
return res_ans
|
||||
|
||||
# 删除上一回合并返回上一回合的问题
|
||||
def undo(self) -> str:
|
||||
self.last_interact_timestamp = int(time.time())
|
||||
|
||||
# 删除上一回合
|
||||
to_delete = self.cut_out(self.prompt, 1, 1024)
|
||||
|
||||
self.prompt = self.prompt.replace(to_delete, '')
|
||||
|
||||
# 返回上一回合的问题
|
||||
return to_delete.split(self.bot_name + ':')[0].split(self.user_name + ':')[1].strip()
|
||||
|
||||
# 从尾部截取prompt里不多于max_rounds个回合,长度不大于max_tokens的字符串
|
||||
# 保证都是完整的对话
|
||||
def cut_out(self, prompt: str, max_rounds: int, max_tokens: int) -> str:
|
||||
|
|
|
@ -120,9 +120,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||
|
||||
config = pkg.utils.context.get_config()
|
||||
|
||||
is_message = True
|
||||
try:
|
||||
|
||||
if text_message.startswith('!') or text_message.startswith("!"): # 指令
|
||||
is_message = False
|
||||
try:
|
||||
logging.info(
|
||||
"[{}]发起指令:{}".format(session_name, text_message[:min(20, len(text_message))] + (
|
||||
|
@ -196,6 +198,11 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||
reply_str += ",当前处于全新会话或不在此页"
|
||||
|
||||
reply = [reply_str]
|
||||
elif cmd == 'resend':
|
||||
session = pkg.openai.session.get_session(session_name)
|
||||
to_send = session.undo()
|
||||
text_message = to_send
|
||||
is_message = True
|
||||
elif cmd == 'fee':
|
||||
api_keys = pkg.utils.context.get_openai_manager().key_mgr.api_key
|
||||
reply_str = "[bot]api-key费用情况(估算):(阈值:{})\n\n".format(
|
||||
|
@ -284,7 +291,8 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
|
|||
mgr.notify_admin("{}指令执行失败:{}".format(session_name, e))
|
||||
logging.exception(e)
|
||||
reply = ["[bot]err:{}".format(e)]
|
||||
else: # 消息
|
||||
|
||||
if is_message: # 消息
|
||||
logging.info("[{}]发送消息:{}".format(session_name, text_message[:min(20, len(text_message))] + (
|
||||
"..." if len(text_message) > 20 else "")))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user