Browse Source

Update README,Optimize format prompt,judge module

Shellmiao 1 year ago
parent
commit
b15d68489a

+ 38 - 12
README.md

@@ -1,6 +1,5 @@
-## 
-
 # ImaGetCha
+
 ## 环境配置
 - 安装python=3.9
 
@@ -24,13 +23,13 @@ python .\main_module.py
 
 #### Chat
 
-需要配置的属性及其作用(带*的为必填)
+需要配置的属性及其作用:
 
-1. *class: 标识符,代表完成同类功能,且维护同一输出文件的chat组件
+1. **class**: 标识符,代表完成同类功能,且维护同一输出文件的chat组件
 
-2. *id: 标识符,每个组件在同一class中的标识符,用于区分同class内不同组件
+2. **id**: 标识符,每个组件在同一class中的标识符,用于区分同class内不同组件
 
-3. input: 输入的数据来源,为{key:value}格式。程序会在运行过程中将value路径对应数据读取,并保存为key=json.load(value)的形式,可在后续过程中被调用
+3. **input**: 输入的数据来源,为{key:value}格式。程序会在运行过程中将value路径对应数据读取,并保存为key=json.load(value)的形式,可在后续过程中被调用
 
    使用示例( json文件均可用此种方法读取到程序运行过程中 ): 
 
@@ -42,7 +41,7 @@ python .\main_module.py
    }
    ```
 
-4. *prompt: 输入chat模型的template模板,结构固定如下
+4. **prompt**: 输入chat模型的template模板,结构固定如下
 
    ```json
    //prompt/input.json
@@ -53,7 +52,7 @@ python .\main_module.py
    }
    ```
 
-5. prompt_input: 定义输入到prompt中的占位符变量,为{key:value}格式。遵循python语法
+5. **prompt_input**: 定义输入到prompt中的占位符变量,为{key:value}格式。遵循python语法
 
    使用示例: 
 
@@ -61,7 +60,7 @@ python .\main_module.py
    2. "interact":"interact['class_output_data']\[-1\]":module_output/Interact_choose_output.json(在input属性中定义的interact对应的json文件)中"class_output_data"对应的数组的最后一个元素
    3. "event":"event['class_output_data']\[-4:\]":module_output/GPT_event_output.json(在input属性中定义的event对应的json文件)中"class_output_data"对应的数组的最后四个元素组成的数组
 
-6. *output: 从以下选择填入(目前支持这些,后续再更新)
+6. **output**: 从以下选择填入(目前支持这些,后续再更新)
 
    1. "{class_output_data}":默认输出到module_output/chat_{classname}_output.json中,并且每次在输出时采取覆盖操作,不保留之前的数据;输出得到的json格式与chat_module输出相同
 
@@ -79,7 +78,7 @@ python .\main_module.py
       }
       ```
 
-7. *next_module: 运行此组件完成后的下一个组件,固定格式如下
+7. **next_module**: 运行此组件完成后的下一个组件,固定格式如下
 
    ```json
    "next_module": {
@@ -95,9 +94,36 @@ python .\main_module.py
    "next_module": None
    ```
 
+#### Judgement
 
+需要配置的属性及其作用:
 
-```json
+1. **class**: 标识符,代表完成同类功能,且维护同一输出文件的chat组件
+2. **id**: 标识符,每个组件在同一class中的标识符,用于区分同class内不同组件
+3. **input**: 输入的数据来源,为{key:value}格式。 与Chat中的input作用相同
+4. **judgement_input**: 定义输入到judgement中的变量,为{key:value}格式。遵循python语法,与prompt_input使用方法相同
+5. **value**: 判断标准,经过python运行后输出为Boolean值的表达式字符串,示例:
+   1. "event['class_output_data']\[-1\]['是否需要玩家选择下一步操作']": 此变量本身为Boolean值
+   2. "value['value']\['生命值'\]<10": 判断语句
+6. **if_true_next**: 格式与next_module相同
+7. **if_false_next**: 格式与next_module相同
 
-```
+#### Interact
+
+需要配置的属性及其作用:
+
+1. **class**: 标识符,代表完成同类功能,且维护同一输出文件的chat组件
+2. **id**: 标识符,每个组件在同一class中的标识符,用于区分同class内不同组件
+3. **input**: 输入的数据来源,为{key:value}格式。 与Chat中的input作用相同
+4. **choices**: 非{key:value}格式,仅指向单个变量,需要读取后为数组。示例: "event['class_output_data']\[-1\]['玩家可以做出的选择']"
+5. **output**: 与Chat中的output相同
+6. **next_module**: 与Chat中的next_module相同
+
+
+
+## TODO
 
+- [ ] 支持从上次中断处继续
+- [ ] 主程序交互优化
+- [ ] 数据处理module
+- [ ] 更多演示case

+ 1 - 1
config/format_config.json

@@ -1,4 +1,4 @@
 {
     "system_template": "将输入字符串转为可以使用json.load读取的字符串,不要输出除了json字符串之外的其他内容",
-    "human_template": "{text}"
+    "human_template": "{text},修复后的json字符串为{json_declare}:"
 }

+ 1 - 0
config/three_kingdoms_product/modules_config.json

@@ -171,6 +171,7 @@
             "input": {
                 "event": "module_output/Chat_event_output.json"
             },
+            "judgement_input":{},
             "value":"event['class_output_data'][-1]['是否需要玩家选择下一步操作']",
             "if_true_next": {
                 "type": "Interact",

+ 51 - 0
config/xi_you/module_output/Chat_event_output.json

@@ -0,0 +1,51 @@
+{
+    "class_output_data": [
+        {
+            "事件": "你们来到了一座高科技城市,城市中心有一座高塔,传说里面有一位神秘的机械大师,可以为你们打造更强大的武器和装备。你们是否要前往高塔寻找机械大师?",
+            "是否需要玩家选择下一步操作": true,
+            "玩家可以做出的选择": [
+                "前往高塔",
+                "不前往高塔"
+            ],
+            "游戏是否结束": false
+        },
+        {
+            "事件": "你们来到了高塔,发现高塔的门口有一位机器人守卫,机器人守卫询问你们的来意,你们该如何回答?",
+            "是否需要玩家选择下一步操作": true,
+            "玩家可以做出的选择": [
+                "说出自己的来意",
+                "攻击机器人守卫",
+                "逃跑"
+            ],
+            "游戏是否结束": false
+        },
+        {
+            "事件": "你们说出了自己的来意,机器人守卫听完后,让你们进入了高塔。高塔内部光线昏暗,四周布满了各种机械设备,你们该如何前进?",
+            "是否需要玩家选择下一步操作": true,
+            "玩家可以做出的选择": [
+                "寻找机械大师的实验室",
+                "随意探索高塔"
+            ],
+            "游戏是否结束": false
+        },
+        {
+            "事件": "你们随意探索高塔,空间听到了一阵机械声响,你们跟着声音走去,发现一台机器人正在进行自我修复,机器人发现了你们,突然向你们发起攻击!",
+            "是否需要玩家选择下一步操作": true,
+            "玩家可以做出的选择": [
+                "攻击机器",
+                "退跑"
+            ],
+            "游戏是否结束": false
+        },
+        {
+            "事件": "你们成功击败了机器人,但是机器人的爆炸导致了高塔的结构出现了问题,你们需要尽快逃离高塔!你们该如何逃离高塔?",
+            "是否需要玩家选择下一步操作": true,
+            "玩家可以做出的选择": [
+                "寻找电梯",
+                "寻找紧急出口",
+                "继续往上爬"
+            ],
+            "游戏是否结束": false
+        }
+    ]
+}

+ 39 - 0
config/xi_you/module_output/Chat_input_output.json

@@ -0,0 +1,39 @@
+{
+    "故事简介": "我们将扮演西游记中的孙悟空,师徒四人前往西天取经。然而,与大家所熟知的西游记不同的是,我们所在的世界是赛博朋克的世界。我们一路上会有怎样搞笑又感人的经历呢?",
+    "角色设定": [
+        {
+            "角色名": "孙悟空",
+            "特征": "拥有七十二变和筋斗云的猴子"
+        },
+        {
+            "角色名": "唐僧",
+            "特征": "慈祥的和尚"
+        },
+        {
+            "角色名": "八戒",
+            "特征": "贪吃爱睡的猪八戒"
+        },
+        {
+            "角色名": "沙僧",
+            "特征": "沉默寡言的沙和尚"
+        }
+    ],
+    "数值系统": [
+        {
+            "数值名称": "经验值",
+            "数值范围": "0-100",
+            "数值含义": "角色的成长值"
+        },
+        {
+            "数值名称": "生命值",
+            "数值范围": "0-100",
+            "数值含义": "角色的生命值"
+        },
+        {
+            "数值名称": "魔法值",
+            "数值范围": "0-100",
+            "数值含义": "角色的魔法值"
+        }
+    ],
+    "游戏通关所需条件": "成功取得真经并回到人间世界"
+}

+ 7 - 0
config/xi_you/module_output/Chat_value_output.json

@@ -0,0 +1,7 @@
+{
+    "value": {
+        "经验值": "100",
+        "生命值": "30",
+        "魔法值": "20"
+    }
+}

+ 8 - 0
config/xi_you/module_output/Interact_choose_output.json

@@ -0,0 +1,8 @@
+{
+    "class_output_data": [
+        "前往高塔",
+        "说出自己的来意",
+        "随意探索高塔",
+        "攻击机器"
+    ]
+}

+ 204 - 0
config/xi_you/modules_config.json

@@ -0,0 +1,204 @@
+{
+    "Chat": [
+        {
+            "class": "input",
+            "id": 1,
+            "input": {
+                "user_input": "user_input.json",
+                "input_module_prompt":"prompt/input.json",
+                "json_declare":"prompt/json_declare.json"
+            },
+            "prompt_input":{
+                "style":"user_input['style']",
+                "story":"user_input['story']",
+                "declare":"input_module_prompt['declare']",
+                "json_declare":"json_declare['json_declare']"
+            },
+            "prompt": "prompt/input.json",
+            "output": "{class_output_data}",
+            "next_module": {
+                "type": "Chat",
+                "class": "value",
+                "id": 1
+            }
+        },
+        {
+            "class": "value",
+            "id": 1,
+            "input": {
+                "intro": "module_output/Chat_input_output.json",
+                "value_1_module_prompt":"prompt/value_1.json"
+            },
+            "prompt_input":{
+                "intro":"intro['故事简介']",
+                "npc":"intro['角色设定']",
+                "value_system":"intro['数值系统']",
+                "target":"intro['游戏通关所需条件']",
+                "output_type":"value_1_module_prompt['output_type']"
+            },
+            "prompt": "prompt/value_1.json",
+            "output": "{class_output_data}",
+            "next_module": {
+                "type": "Chat",
+                "class": "event",
+                "id": 1
+            }
+        },
+        {
+            "class": "event",
+            "id": 1,
+            "input": {
+                "user_input": "user_input.json",
+                "event_module_prompt":"prompt/event_1.json",
+                "intro": "module_output/Chat_input_output.json",
+                "value": "module_output/Chat_value_output.json",
+                "json_declare":"prompt/json_declare.json"
+            },
+            "prompt_input":{
+                "style":"user_input['style']",
+                "story":"user_input['story']",
+                "intro":"intro['故事简介']",
+                "npc":"intro['角色设定']",
+                "value_system":"intro['数值系统']",
+                "target":"intro['游戏通关所需条件']",
+                "output_type":"event_module_prompt['output_type']",
+                "json_declare":"json_declare['json_declare']",
+                "value":"value['value']"
+            },
+            "prompt": "prompt/event_1.json",
+            "output": "{class_output_data_append}",
+            "next_module": {
+                "type": "Chat",
+                "class": "value",
+                "id": 2
+            }
+        },
+        {
+            "class": "value",
+            "id": 2,
+            "input": {
+                "intro": "module_output/Chat_input_output.json",
+                "value_1_module_prompt":"prompt/value_1.json",
+                "value": "module_output/Chat_value_output.json",
+                "event": "module_output/Chat_event_output.json"
+            },
+            "prompt": "prompt/value_2.json",
+            "prompt_input":{
+                "intro":"intro['故事简介']",
+                "npc":"intro['角色设定']",
+                "value_system":"intro['数值系统']",
+                "target":"intro['游戏通关所需条件']",
+                "event":"event['class_output_data'][-4:]",
+                "value":"value['value']",
+                "output_type":"value_1_module_prompt['output_type']"
+            },
+            "output": "{class_output_data}",
+            "next_module": {
+                "type": "Judgement",
+                "class": "Boolean",
+                "id": 1
+            }
+        },
+        {
+            "class": "event",
+            "id": 2,
+            "input": {
+                "user_input": "user_input.json",
+                "event_module_prompt":"prompt/event_2.json",
+                "intro": "module_output/Chat_input_output.json",
+                "value": "module_output/Chat_value_output.json",
+                "json_declare":"prompt/json_declare.json",
+                "event": "module_output/Chat_event_output.json",
+                "interact":"module_output/Interact_choose_output.json"
+            },
+            "prompt_input":{
+                "style":"user_input['style']",
+                "story":"user_input['story']",
+                "intro":"intro['故事简介']",
+                "npc":"intro['角色设定']",
+                "value_system":"intro['数值系统']",
+                "target":"intro['游戏通关所需条件']",
+                "output_type":"event_module_prompt['output_type']",
+                "json_declare":"json_declare['json_declare']",
+                "value":"value['value']",
+                "event":"event['class_output_data'][-4:]",
+                "interact":"interact['class_output_data'][-1]"
+            },
+            "prompt": "prompt/event_2.json",
+            "output": "{class_output_data_append}",
+            "next_module": {
+                "type": "Chat",
+                "class": "value",
+                "id": 2
+            }
+        },
+        {
+            "class": "event",
+            "id": 3,
+            "input": {
+                "user_input": "user_input.json",
+                "event_module_prompt":"prompt/event_3.json",
+                "intro": "module_output/Chat_input_output.json",
+                "value": "module_output/Chat_value_output.json",
+                "json_declare":"prompt/json_declare.json",
+                "event": "module_output/Chat_event_output.json"
+            },
+            "prompt_input":{
+                "style":"user_input['style']",
+                "story":"user_input['story']",
+                "intro":"intro['故事简介']",
+                "npc":"intro['角色设定']",
+                "value_system":"intro['数值系统']",
+                "target":"intro['游戏通关所需条件']",
+                "output_type":"event_module_prompt['output_type']",
+                "json_declare":"json_declare['json_declare']",
+                "value":"value['value']",
+                "event":"event['class_output_data'][-4:]"
+            },
+            "prompt": "prompt/event_3.json",
+            "output": "{class_output_data_append}",
+            "next_module": {
+                "type": "Chat",
+                "class": "value",
+                "id": 2
+            }
+        }
+    ],
+    "Judgement": [
+        {
+            "class": "Boolean",
+            "id": 1,
+            "input": {
+                "event": "module_output/Chat_event_output.json"
+            },
+            "judgement_input":{},
+            "value":"event['class_output_data'][-1]['是否需要玩家选择下一步操作']",
+            "if_true_next": {
+                "type": "Interact",
+                "class": "choose",
+                "id": 1
+            },
+            "if_false_next": {
+                "type": "Chat",
+                "class": "event",
+                "id": 3
+            }
+        }
+    ],
+    "Interact": [
+        {
+            "class": "choose",
+            "id": 1,
+            "input": {
+                "event": "module_output/Chat_event_output.json"
+            },
+            "choices": "event['class_output_data'][-1]['玩家可以做出的选择']",
+            "output": "{class_output_data_append}",
+            "next_module": {
+                "type": "Chat",
+                "class": "event",
+                "id": 2
+            }
+        }
+    ]
+}

+ 5 - 0
config/xi_you/prompt/event_1.json

@@ -0,0 +1,5 @@
+{
+    "output_type": "{\"事件\": \"字符串格式,这是展示给玩家的,讲述了玩家当前遇到的事件,例如“0岁,你出生于颍川一个富贵之家...”。出现新的人物时需要在事件中对新的人物进行描写,并在当前角色设定中添加新的角色\",\"是否需要玩家选择下一步操作\": \"Boolean格式\",\"玩家可以做出的选择\": \"数组格式,玩家可以做出的有限个选择,如果不需要玩家做选择则返回空数组\",\"游戏是否结束\": \"Boolean格式,游戏是否结束\"}",
+    "system_template": "我正在生成一个文字冒险游戏,我将输入游戏当前信息与当前游戏的风格、简介,需要你根据游戏当前信息生成玩家接下来遇到的下一个事件,以如下格式输出JSON:{output_type},严格按照格式输出,不要输出除了json字符串之外的其他内容",
+    "human_template": "游戏风格:{style};游戏参考:{story};故事简介:{intro};角色设定:{npc};数值系统:{value_system};当前数值:{value},玩家遇到的下一个事件的json输出为{json_declare}:"
+}

+ 6 - 0
config/xi_you/prompt/event_2.json

@@ -0,0 +1,6 @@
+{
+    "output_type": "{\"事件\": \"字符串格式,这是展示给玩家的,讲述了玩家当前遇到的事件,例如“0岁,你出生于颍川一个富贵之家...”。出现新的人物时需要在事件中对新的人物进行描写,并在当前角色设定中添加新的角色\",\"是否需要玩家选择下一步操作\": \"Boolean格式\",\"玩家可以做出的选择\": \"数组格式,玩家可以做出的有限个选择,如果不需要玩家做选择则返回空数组\",\"游戏是否结束\": \"Boolean格式,游戏是否结束\"}",
+    "system_template": "我正在生成一个文字冒险游戏,我将输入游戏当前信息与当前游戏的风格、简介,需要你根据游戏当前信息生成玩家接下来遇到的下一个事件,以如下格式输出JSON:{output_type},严格按照格式输出,不要输出除了json字符串之外的其他内容",
+    "human_template": "游戏风格:{style};游戏参考:{story};故事简介:{intro};角色设定:{npc};数值系统:{value_system};当前数值:{value};游戏发生的事件:{event};玩家对最后一次事件做出的选择:{interact};玩家遇到的下一个事件的json输出为{json_declare}:"
+    
+}

+ 5 - 0
config/xi_you/prompt/event_3.json

@@ -0,0 +1,5 @@
+{
+    "output_type": "{\"事件\": \"字符串格式,这是展示给玩家的,讲述了玩家当前遇到的事件,例如“0岁,你出生于颍川一个富贵之家...”。出现新的人物时需要在事件中对新的人物进行描写,并在当前角色设定中添加新的角色\",\"是否需要玩家选择下一步操作\": \"Boolean格式\",\"玩家可以做出的选择\": \"数组格式,玩家可以做出的有限个选择,如果不需要玩家做选择则返回空数组\",\"游戏是否结束\": \"Boolean格式,游戏是否结束\"}",
+    "system_template": "我正在生成一个文字冒险游戏,我将输入游戏当前信息与当前游戏的风格、简介,需要你根据游戏当前信息生成玩家接下来遇到的下一个事件,以如下格式输出JSON:{output_type},严格按照格式输出,不要输出除了json字符串之外的其他内容",
+    "human_template": "游戏风格:{style};游戏参考:{story};故事简介:{intro};角色设定:{npc};数值系统:{value_system};当前数值:{value};游戏发生的事件:{event};玩家遇到的下一个事件的json输出为{json_declare}:"
+}

+ 5 - 0
config/xi_you/prompt/input.json

@@ -0,0 +1,5 @@
+{
+    "declare":"{'故事简介': '字符串格式,这是展示给玩家的故事简介与游戏目标','角色设定': '数组格式,游戏中的npc角色设定,包括角色的名字、特征;不包含玩家所操控的角色','数值系统': '数组格式,数值系统包括游戏中的数值名称、数值范围、数值含义,例如装备系统、官职系统等','游戏通关所需条件': '字符串格式,游戏结束的条件,例如“成为了诸侯王'}",
+    "system_template": "以如下格式输出可以被json.loads读取的JSON字符串:{declare}",
+    "human_template": "我希望生成一个文字冒险游戏,以下是对游戏故事的要求:故事风格:{style},故事参考:{story}。你生成的可以直接被json.loads读取的不带换行符的JSON字符串为{json_declare}:"
+}

+ 3 - 0
config/xi_you/prompt/json_declare.json

@@ -0,0 +1,3 @@
+{
+    "json_declare":"(示例:{\"key1\":\"value1\",\"key2\":\"value2\"})"
+}

+ 5 - 0
config/xi_you/prompt/value_1.json

@@ -0,0 +1,5 @@
+{
+    "output_type": "示例:{\"value\":{\"数值名称\":\"数值大小\"}",
+    "system_template": "输出JSON",
+    "human_template": "我正在生成一个文字游戏,故事简介:{intro};角色设定:{npc};数值系统:{value_system};游戏通关所需条件:{target};需要你根据游戏当前信息对玩家数值进行初始化,不用输出除了value之外的其他内容,你的JSON输出为{output_type}:"
+}

+ 5 - 0
config/xi_you/prompt/value_2.json

@@ -0,0 +1,5 @@
+{
+    "output_type": "{\"value\":{\"数值名称\":\"数值大小\"}",
+    "system_template": "输出JSON",
+    "human_template": "我正在生成一个文字游戏,故事简介:{intro};角色设定:{npc};数值系统:{value_system};游戏通关所需条件:{target};游戏发生的事件:{event};玩家当前数值:{value};需要你根据游戏最后发生的事件对玩家数值进行修改,不用输出除了value之外的其他内容,你的JSON输出为{output_type}:"
+}

+ 4 - 0
config/xi_you/user_input.json

@@ -0,0 +1,4 @@
+{
+    "style": "西游记,搞笑,孙悟空,赛博朋克",
+    "story": "我将扮演西游记中的孙悟空,我们师徒四人前往西天取经,然而,与大家所熟知的西游记不同的是,我们所在的世界,是赛博朋克的世界。我们一路上会有怎样搞笑又感人的经历呢?"
+}

+ 4 - 4
main_module.py

@@ -35,15 +35,15 @@ configuration=Configuration(args.name)
 while True:
     if next_module["type"]=="Chat":
         input_path,prompt_input_declare,prompt_path,output,next_module_temp=configuration.read_chat_config(next_module["class"],next_module["id"])
-        prompt_input_value=configuration.prompt_input_process(input_path,prompt_input_declare)
+        prompt_input_value=configuration.input_process(input_path,prompt_input_declare)
         prompt=configuration.read_prompt(prompt_path)
         chat_module(next_module["class"],next_module["id"],prompt_input_value,prompt,output)
         next_module=next_module_temp
 
     elif next_module["type"]=="Judgement":
-        input,value,judgement=configuration.read_judgement_config(next_module["class"],next_module["id"])
-        input_value=configuration.judgement_input_process(input,value)
-        next_module=judgment_module(next_module["class"],input_value,judgement)
+        input_path,judgement_input_declare,value,judgement=configuration.read_judgement_config(next_module["class"],next_module["id"])
+        judgement_input_value=configuration.input_process(input_path,judgement_input_declare)
+        next_module=judgment_module(judgement_input_value,value,judgement)
     elif next_module["type"]=="Interact":
         input,choices,output,next_module_temp=configuration.read_interact_config(next_module["class"],next_module["id"])
         choices_value=configuration.interact_input_process(input,choices)

+ 7 - 6
modules/conditional_judgement_module.py

@@ -1,6 +1,7 @@
-def judgment_module(classname,value,Judgement):
-    if classname=="Boolean":
-        if value:
-            return Judgement["if_true_next"]
-        else:
-            return Judgement["if_false_next"]
+def judgment_module(judgement_input,value,Judgement):
+    for judgement_input_key, judgement_input_value in judgement_input.items():
+        globals()[judgement_input_key] = judgement_input_value
+    if eval(value):
+        return Judgement["if_true_next"]
+    else:
+        return Judgement["if_false_next"]

+ 2 - 9
utils/configuration.py

@@ -45,7 +45,7 @@ class Configuration:
             with open(file_path, 'w', encoding='utf-8') as f:
                 json.dump(data, f, ensure_ascii=False, indent=4)
 
-    def prompt_input_process(self,input,prompt_input):
+    def input_process(self,input,prompt_input):
         for input_key, input_value in input.items():
             with open('config/'+self.game_name+'/'+input_value,encoding='utf-8') as f:
                 globals()[input_key] = json.load(f)
@@ -73,14 +73,7 @@ class Configuration:
         judgements=data["Judgement"]
         for judgement in judgements:
             if judgement["id"]==id and judgement["class"]==classname:
-                return judgement["input"],judgement["value"],judgement
-
-    def judgement_input_process(self,input,value):
-        for input_key, input_value in input.items():
-            with open('config/'+self.game_name+'/'+input_value,encoding='utf-8') as f:
-                globals()[input_key] = json.load(f)
-        input_value = eval(value.format(**locals()))
-        return input_value
+                return judgement["input"],judgement["judgement_input"],judgement["value"],judgement
     
     def read_interact_config(self,classname,id):
         with open('config/'+self.game_name+'/modules_config.json',encoding='utf-8') as f:

+ 4 - 2
utils/format_error_data.py

@@ -16,6 +16,8 @@ def format_error_data(text):
 
     configuration=Configuration()
     data=configuration.read_json("format_config.json")
+    
+    json_declare="(示例:{\"key1\":\"value1\",\"key2\":\"value2\"})"
 
     system_template = data["system_template"]
     system_message_prompt = SystemMessagePromptTemplate.from_template(
@@ -27,8 +29,8 @@ def format_error_data(text):
     chat_prompt = ChatPromptTemplate.from_messages(
         [system_message_prompt, human_message_prompt])
 
-    rsp = chat(
-        chat_prompt.format_prompt(text=text).to_messages())
+    input_prompt=chat_prompt.format_prompt(text=text,json_declare=json_declare).to_messages()
+    rsp = chat(input_prompt)
     print('[修复]--------------------------Chat得到--------------------------')
     print(rsp.content)
     try: