mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 添加continue命令
This commit is contained in:
parent
e26664aa51
commit
dc1fd73ebb
|
@ -159,9 +159,14 @@ class ChatCompletionRequest(RequestBase):
|
|||
logging.info("执行函数调用: name={}, arguments={}".format(func_name, arguments))
|
||||
|
||||
# 执行函数调用
|
||||
ret = execute_function(func_name, arguments)
|
||||
ret = ""
|
||||
try:
|
||||
ret = execute_function(func_name, arguments)
|
||||
|
||||
logging.info("函数执行完成。")
|
||||
logging.info("函数执行完成。")
|
||||
except Exception as e:
|
||||
ret = "error: execute function failed: {}".format(str(e))
|
||||
logging.error("函数执行失败: {}".format(str(e)))
|
||||
|
||||
self.append_message(
|
||||
role="function",
|
||||
|
|
|
@ -194,7 +194,7 @@ class Session:
|
|||
|
||||
# 请求回复
|
||||
# 这个函数是阻塞的
|
||||
def append(self, text: str) -> str:
|
||||
def append(self, text: str=None) -> str:
|
||||
"""向session中添加一条消息,返回接口回复"""
|
||||
|
||||
self.last_interact_timestamp = int(time.time())
|
||||
|
@ -270,7 +270,8 @@ class Session:
|
|||
# 将此次对话的双方内容加入到prompt中
|
||||
# self.prompt.append({'role': 'user', 'content': text})
|
||||
# self.prompt.append({'role': 'assistant', 'content': res_ans})
|
||||
self.prompt.append({'role': 'user', 'content': text})
|
||||
if text:
|
||||
self.prompt.append({'role': 'user', 'content': text})
|
||||
# 添加pending_msgs
|
||||
self.prompt += pending_msgs
|
||||
|
||||
|
@ -331,12 +332,13 @@ class Session:
|
|||
result_prompt = self.default_prompt + changable_prompts
|
||||
|
||||
# 添加当前问题
|
||||
result_prompt.append(
|
||||
{
|
||||
'role': 'user',
|
||||
'content': msg
|
||||
}
|
||||
)
|
||||
if msg:
|
||||
result_prompt.append(
|
||||
{
|
||||
'role': 'user',
|
||||
'content': msg
|
||||
}
|
||||
)
|
||||
|
||||
logging.debug("cut_out: {}".format(json.dumps(result_prompt, ensure_ascii=False, indent=4)))
|
||||
|
||||
|
|
27
pkg/qqbot/cmds/session/continue.py
Normal file
27
pkg/qqbot/cmds/session/continue.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from ..aamgr import AbstractCommandNode, Context
|
||||
|
||||
|
||||
@AbstractCommandNode.register(
|
||||
parent=None,
|
||||
name="continue",
|
||||
description="继续未完成的响应",
|
||||
usage="!continue",
|
||||
aliases=[],
|
||||
privilege=1
|
||||
)
|
||||
class ContinueCommand(AbstractCommandNode):
|
||||
@classmethod
|
||||
def process(cls, ctx: Context) -> tuple[bool, list]:
|
||||
import pkg.openai.session
|
||||
import config
|
||||
session_name = ctx.session_name
|
||||
|
||||
reply = []
|
||||
|
||||
session = pkg.openai.session.get_session(session_name)
|
||||
|
||||
text = session.append()
|
||||
|
||||
reply = [text]
|
||||
|
||||
return True, reply
|
Loading…
Reference in New Issue
Block a user