From dc1fd73ebb7c587fd29d6a68d8469e8fcaefcf1d Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Mon, 31 Jul 2023 15:17:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0continue=E5=91=BD?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/openai/api/chat_completion.py | 9 +++++++-- pkg/openai/session.py | 18 ++++++++++-------- pkg/qqbot/cmds/session/continue.py | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 pkg/qqbot/cmds/session/continue.py diff --git a/pkg/openai/api/chat_completion.py b/pkg/openai/api/chat_completion.py index 9b4b0c24..e6d43165 100644 --- a/pkg/openai/api/chat_completion.py +++ b/pkg/openai/api/chat_completion.py @@ -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", diff --git a/pkg/openai/session.py b/pkg/openai/session.py index 179d4c7b..ac85c408 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -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))) diff --git a/pkg/qqbot/cmds/session/continue.py b/pkg/qqbot/cmds/session/continue.py new file mode 100644 index 00000000..32fa8a2d --- /dev/null +++ b/pkg/qqbot/cmds/session/continue.py @@ -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 \ No newline at end of file From 0fb5bfda20161ac5dff9de945e2c146fdd526e4f Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Mon, 31 Jul 2023 15:20:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0tiktoken=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/update-cmdpriv-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-cmdpriv-template.yml b/.github/workflows/update-cmdpriv-template.yml index b8e77f0c..522f03b8 100644 --- a/.github/workflows/update-cmdpriv-template.yml +++ b/.github/workflows/update-cmdpriv-template.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install --upgrade yiri-mirai openai colorlog func_timeout dulwich Pillow CallingGPT + python -m pip install --upgrade yiri-mirai openai colorlog func_timeout dulwich Pillow CallingGPT tiktoken - name: Copy Scripts run: | From 3f41b94da568f13c6fb4808b2d2791fa7eca88b4 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Mon, 31 Jul 2023 15:23:42 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/cmds/plugin/plugin.py | 2 +- pkg/qqbot/cmds/session/continue.py | 2 +- res/wiki/功能使用.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/qqbot/cmds/plugin/plugin.py b/pkg/qqbot/cmds/plugin/plugin.py index f65bab5f..9818b7c7 100644 --- a/pkg/qqbot/cmds/plugin/plugin.py +++ b/pkg/qqbot/cmds/plugin/plugin.py @@ -12,7 +12,7 @@ import pkg.utils.updater as updater description="插件管理", usage="!plugin\n!plugin get <插件仓库地址>\n!plugin update\n!plugin del <插件名>\n!plugin on <插件名>\n!plugin off <插件名>", aliases=[], - privilege=2 + privilege=1 ) class PluginCommand(AbstractCommandNode): @classmethod diff --git a/pkg/qqbot/cmds/session/continue.py b/pkg/qqbot/cmds/session/continue.py index 32fa8a2d..4566ec90 100644 --- a/pkg/qqbot/cmds/session/continue.py +++ b/pkg/qqbot/cmds/session/continue.py @@ -24,4 +24,4 @@ class ContinueCommand(AbstractCommandNode): reply = [text] - return True, reply \ No newline at end of file + return True, reply diff --git a/res/wiki/功能使用.md b/res/wiki/功能使用.md index df469bcf..67b7ce89 100644 --- a/res/wiki/功能使用.md +++ b/res/wiki/功能使用.md @@ -180,6 +180,7 @@ !draw <提示语> 进行绘图 !version 查看当前版本并检查更新 !resend 重新回复上一个问题 +!continue 继续响应未完成的回合(通常用于内容函数继续调用) !plugin 用法请查看插件使用页的`管理`章节 !default 查看可用的情景预设值 ``` From 13a1e15f24e9ae091aec96d062d9fcc3a1c79dfa Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot Date: Mon, 31 Jul 2023 07:24:14 +0000 Subject: [PATCH 4/4] Update cmdpriv-template.json --- res/templates/cmdpriv-template.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/res/templates/cmdpriv-template.json b/res/templates/cmdpriv-template.json index 18bc3db9..e0944bda 100644 --- a/res/templates/cmdpriv-template.json +++ b/res/templates/cmdpriv-template.json @@ -2,12 +2,13 @@ "comment": "以下为命令权限,请设置到cmdpriv.json中。关于此功能的说明,请查看:https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E5%91%BD%E4%BB%A4%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6", "draw": 1, "func": 1, - "plugin": 2, + "plugin": 1, "plugin.get": 2, "plugin.update": 2, "plugin.del": 2, "plugin.off": 2, "plugin.on": 2, + "continue": 1, "default": 1, "default.set": 2, "del": 1,