Shellmiao 5800128b75 Update example output | há 1 ano atrás | |
---|---|---|
config | há 1 ano atrás | |
modules | há 1 ano atrás | |
non_module_old | há 1 ano atrás | |
old | há 1 ano atrás | |
utils | há 1 ano atrás | |
.gitignore | há 1 ano atrás | |
README.md | há 1 ano atrás | |
main_module.py | há 1 ano atrás | |
requirement.txt | há 1 ano atrás |
安装python=3.9
安装python依赖库
pip install -r requirement.txt
python .\main_module.py -h
---usage: main_module.py [-h] -n NAME -t TYPE -c CLASSNAME -i ID
---生成文字游戏
---optional arguments:
--- -h, --help show this help message and exit
--- -n NAME, --name NAME config文件夹中配置的文件夹名称
--- -t TYPE, --type TYPE 开始的第一个组件的类型
--- -c CLASSNAME, --classname CLASSNAME
--- 开始的第一个组件的classname
--- -i ID, --id ID 开始的第一个组件的id
python .\main_module.py -n example -t Chat -c input -i 1
重新开始需要删除游戏配置文件中的module_output文件夹中的内容,其中保存了游戏进度; 若不删除,建议根据进度自行修改启动命令中的-t Chat -c input -i 1
部分,使之在正确的组件上启动
通过配置config中的json文件来配置模型结构,下面使用一个例子来介绍如何配置运行结构
需要配置的属性及其作用:
class: 标识符,代表完成同类功能,且维护同一输出文件的chat组件
id: 标识符,每个组件在同一class中的标识符,用于区分同class内不同组件
input: 输入的数据来源,为{key:value}格式。程序会在运行过程中将value路径对应数据读取,并保存为key=json.load(value)的形式,可在后续过程中被调用
使用示例( json文件均可用此种方法读取到程序运行过程中 ):
"input": {
"user_input": "user_input.json",
"input_module_prompt":"prompt/input.json",
"json_declare":"prompt/json_declare.json"
}
//prompt/input.json
{
"system_template": "系统消息,可以在其中加入{占位符},必须填写;会被自动填入prompt中",
"human_template": "用户消息,可以在其中加入{占位符},必须填写;会被自动填入prompt中",
"其他key": "其他value, 不会被自动当成prompt加入到chat_module中,但可以被当成正常的input读取"
}
使用示例:
"event":"event['class_output_data'][-4:]":module_output/GPT_event_output.json(在input属性中定义的event对应的json文件)中"class_output_data"对应的数组的最后四个元素组成的数组
output: 从以下选择填入(目前支持这些,后续再更新)
{chat_module_output}
{
"class_output_data": [
...previous_data,{chat_module_output}
]
}
next_module: 运行此组件完成后的下一个组件,固定格式如下
"next_module": {
"type": "Chat"/"Judgement"/"Interact",
"class": "classname",
"id": id
}
若无下一个组件,则填入
"next_module": {
"type": "End"
}
需要配置的属性及其作用:
需要配置的属性及其作用:
{
"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": "Judgement",
"class": "Boolean",
"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": "Judgement",
"class": "Boolean",
"id": 2
}
}
],
"Judgement": [
{
"class": "Boolean",
"id": 1,
"input": {
"event": "module_output/Chat_event_output.json"
},
"judgement_input":{
"last_event":"event['class_output_data'][-1]"
},
"value":"last_event['是否需要玩家选择下一步操作']",
"if_true_next": {
"type": "Interact",
"class": "choose",
"id": 1
},
"if_false_next": {
"type": "Chat",
"class": "event",
"id": 3
}
},
{
"class": "Boolean",
"id": 2,
"input": {
"event": "module_output/Chat_event_output.json"
},
"judgement_input":{
"last_event":"event['class_output_data'][-1]"
},
"value":"last_event['游戏是否结束']",
"if_true_next": {"type":"End"},
"if_false_next": {
"type": "Chat",
"class": "value",
"id": 2
}
}
],
"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
}
}
]
}
{
"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": "outline",
"id": 1
}
},
{
"class": "outline",
"id": 1,
"input": {
"user_input": "user_input.json",
"intro": "module_output/Chat_input_output.json",
"outline_module_prompt":"prompt/outline.json"
},
"prompt_input":{
"style":"user_input['style']",
"story":"user_input['story']",
"intro":"intro['故事简介']",
"npc":"intro['角色设定']",
"value_system":"intro['数值系统']",
"target":"intro['游戏通关所需条件']",
"output_type":"outline_module_prompt['output_type']"
},
"prompt": "prompt/outline.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",
"outline":"module_output/Chat_outline_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['游戏通关所需条件']",
"outline":"outline['outline']",
"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",
"outline":"module_output/Chat_outline_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['游戏通关所需条件']",
"outline":"outline['outline']",
"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": "Judgement",
"class": "Boolean",
"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",
"outline":"module_output/Chat_outline_output.json"
},
"prompt_input":{
"style":"user_input['style']",
"story":"user_input['story']",
"intro":"intro['故事简介']",
"npc":"intro['角色设定']",
"value_system":"intro['数值系统']",
"target":"intro['游戏通关所需条件']",
"outline":"outline['outline']",
"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": "Judgement",
"class": "Boolean",
"id": 2
}
}
],
"Judgement": [
{
"class": "Boolean",
"id": 1,
"input": {
"event": "module_output/Chat_event_output.json"
},
"judgement_input":{
"last_event":"event['class_output_data'][-1]"
},
"value":"last_event['是否需要玩家选择下一步操作']",
"if_true_next": {
"type": "Interact",
"class": "choose",
"id": 1
},
"if_false_next": {
"type": "Chat",
"class": "event",
"id": 3
}
},
{
"class": "Boolean",
"id": 2,
"input": {
"event": "module_output/Chat_event_output.json"
},
"judgement_input":{
"last_event":"event['class_output_data'][-1]"
},
"value":"last_event['游戏是否结束']",
"if_true_next": {"type":"End"},
"if_false_next": {
"type": "Chat",
"class": "value",
"id": 2
}
}
],
"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
}
}
]
}