From 9fe0ee2b779f2b41c2e271c709a4829d0ec3f67e Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Tue, 14 Nov 2023 21:06:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E4=BD=BF=E7=94=A8system=20role?= =?UTF-8?q?=E7=BD=AE=E5=85=A5default=20prompt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 2 +- pkg/openai/dprompt.py | 20 +++----------------- pkg/openai/session.py | 1 + 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/config-template.py b/config-template.py index c589222e..7ef2f784 100644 --- a/config-template.py +++ b/config-template.py @@ -114,7 +114,7 @@ # # 还可以加载文件中的预设文字,使用方法请查看:https://github.com/RockChinQ/QChatGPT/wiki/%E5%8A%9F%E8%83%BD%E4%BD%BF%E7%94%A8#%E9%A2%84%E8%AE%BE%E6%96%87%E5%AD%97 default_prompt = { - "default": "如果我之后想获取帮助,请你说“输入!help获取帮助”", + "default": "如果用户之后想获取帮助,请你说“输入!help获取帮助”。", } # 情景预设格式 diff --git a/pkg/openai/dprompt.py b/pkg/openai/dprompt.py index adb0a4d8..ec1dbf2f 100644 --- a/pkg/openai/dprompt.py +++ b/pkg/openai/dprompt.py @@ -16,10 +16,6 @@ # __scenario_from_files__ = {} -__universal_first_reply__ = "ok, I'll follow your commands." -"""通用首次回复""" - - class ScenarioMode: """情景预设模式抽象类""" @@ -66,17 +62,13 @@ class NormalScenarioMode(ScenarioMode): """普通情景预设模式""" def __init__(self): - global __universal_first_reply__ # 加载config中的default_prompt值 if type(config.default_prompt) == str: self.using_prompt_name = "default" self.prompts = {"default": [ { - "role": "user", + "role": "system", "content": config.default_prompt - },{ - "role": "assistant", - "content": __universal_first_reply__ } ]} @@ -84,11 +76,8 @@ def __init__(self): for key in config.default_prompt: self.prompts[key] = [ { - "role": "user", + "role": "system", "content": config.default_prompt[key] - },{ - "role": "assistant", - "content": __universal_first_reply__ } ] @@ -98,11 +87,8 @@ def __init__(self): with open(os.path.join("prompts", file), encoding="utf-8") as f: self.prompts[file] = [ { - "role": "user", + "role": "system", "content": f.read() - },{ - "role": "assistant", - "content": __universal_first_reply__ } ] diff --git a/pkg/openai/session.py b/pkg/openai/session.py index 5c351478..498b9082 100644 --- a/pkg/openai/session.py +++ b/pkg/openai/session.py @@ -241,6 +241,7 @@ def query(self, text: str=None) -> tuple[str, str, list[str]]: if event.get_return_value('text_message') is not None: text = event.get_return_value('text_message') + # 裁剪messages到合适长度 prompts, _ = self.cut_out(text, max_length, local_default_prompt, local_prompt) res_text = "" From d2776cc1e68d95000dd7e7542f9668d9f54c6606 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 14 Nov 2023 13:06:22 +0000 Subject: [PATCH 2/3] Update override-all.json --- override-all.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/override-all.json b/override-all.json index 595459e8..db9227c2 100644 --- a/override-all.json +++ b/override-all.json @@ -24,7 +24,7 @@ "switch_strategy": "active", "admin_qq": 0, "default_prompt": { - "default": "如果我之后想获取帮助,请你说“输入!help获取帮助”" + "default": "如果用户之后想获取帮助,请你说“输入!help获取帮助”。" }, "preset_mode": "normal", "response_rules": { From 5abca8443713d30789b2cab5367f36862f1886bb Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Tue, 14 Nov 2023 21:35:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?debug:=20=E6=B7=BB=E5=8A=A0=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/openai/api/model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/openai/api/model.py b/pkg/openai/api/model.py index 3fd71fea..f2c04ccc 100644 --- a/pkg/openai/api/model.py +++ b/pkg/openai/api/model.py @@ -21,6 +21,7 @@ def _next_key(self): def _req(self, **kwargs): """处理代理问题""" + logging.debug("请求接口参数: %s", str(kwargs)) import config ret = self.req_func(**kwargs)