From 54cc75506f54b5a53a9b2d7c4ea51ad46cc4e58c Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Fri, 10 Mar 2023 23:26:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=82=A8=E5=AD=98=E9=BB=98=E8=AE=A4=E7=9A=84json=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E6=83=85=E6=99=AF=E9=A2=84=E8=AE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- main.py | 4 ++++ pkg/openai/dprompt.py | 4 +--- .../{default.json => default-template.json} | 22 +++++++++---------- 4 files changed, 19 insertions(+), 15 deletions(-) rename scenario/{default.json => default-template.json} (97%) diff --git a/.gitignore b/.gitignore index 362973b7..10cc092c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ prompts/ logs/ sensitive.json temp/ -current_tag \ No newline at end of file +current_tag +scenario/ +!scenario/default-template.json \ No newline at end of file diff --git a/main.py b/main.py index bfdd7a80..de0d5a99 100644 --- a/main.py +++ b/main.py @@ -332,6 +332,10 @@ if __name__ == '__main__': if not os.path.exists("sensitive.json"): shutil.copy("sensitive-template.json", "sensitive.json") + # 检查是否有scenario/default.json + if not os.path.exists("scenario/default.json"): + shutil.copy("scenario/default-template.json", "scenario/default.json") + # 检查temp目录 if not os.path.exists("temp/"): os.mkdir("temp/") diff --git a/pkg/openai/dprompt.py b/pkg/openai/dprompt.py index 4768e599..152bfcab 100644 --- a/pkg/openai/dprompt.py +++ b/pkg/openai/dprompt.py @@ -88,10 +88,8 @@ def get_prompt(name: str = None) -> list: json_content = json.load(f) logging.debug('succeed to load json: {}'.format(json_file)) return json_content['prompt'] - except FileNotFoundError: - - raise KeyError("未找到Json情景预设: " + name) + raise KeyError("未找到JSON情景预设: " + name) # 默认预设方式 elif preset_mode == 'default': diff --git a/scenario/default.json b/scenario/default-template.json similarity index 97% rename from scenario/default.json rename to scenario/default-template.json index 3dcfd9ab..d9b7267a 100644 --- a/scenario/default.json +++ b/scenario/default-template.json @@ -1,12 +1,12 @@ -{ - "prompt": [ - { - "role": "system", - "content": "You are a helpful assistant. 如果我需要帮助,你要说“输入!help获得帮助”" - }, - { - "role": "assistant", - "content": "好的,我是一个能干的AI助手。 如果你需要帮助,我会说“输入!help获得帮助”" - } - ] +{ + "prompt": [ + { + "role": "system", + "content": "You are a helpful assistant. 如果我需要帮助,你要说“输入!help获得帮助”" + }, + { + "role": "assistant", + "content": "好的,我是一个能干的AI助手。 如果你需要帮助,我会说“输入!help获得帮助”" + } + ] } \ No newline at end of file