Skip to content

Commit

Permalink
refactor: 使用system role置入default prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Nov 14, 2023
1 parent b68daac commit 9fe0ee2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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获取帮助”",
}

# 情景预设格式
Expand Down
20 changes: 3 additions & 17 deletions pkg/openai/dprompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# __scenario_from_files__ = {}


__universal_first_reply__ = "ok, I'll follow your commands."
"""通用首次回复"""


class ScenarioMode:
"""情景预设模式抽象类"""

Expand Down Expand Up @@ -66,29 +62,22 @@ 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__
}
]}

elif type(config.default_prompt) == dict:
for key in config.default_prompt:
self.prompts[key] = [
{
"role": "user",
"role": "system",
"content": config.default_prompt[key]
},{
"role": "assistant",
"content": __universal_first_reply__
}
]

Expand All @@ -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__
}
]

Expand Down
1 change: 1 addition & 0 deletions pkg/openai/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 9fe0ee2

Please sign in to comment.