main_module.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from modules.conditional_judgement_module import judgment_module
  2. from modules.chat_module import chat_module
  3. from modules.interact_module import interact_module
  4. from utils.configuration import Configuration
  5. import argparse
  6. parser = argparse.ArgumentParser(description="生成文字游戏")
  7. parser.add_argument("-n",
  8. "--name",
  9. required=True,
  10. help="config文件夹中配置的文件夹名称")
  11. parser.add_argument("-t",
  12. "--type",
  13. required=True,
  14. help="开始的第一个组件的类型")
  15. parser.add_argument("-c",
  16. "--classname",
  17. required=True,
  18. help="开始的第一个组件的classname")
  19. parser.add_argument("-i",
  20. "--id",
  21. required=True,
  22. help="开始的第一个组件的id")
  23. args = parser.parse_args()
  24. next_module = {
  25. "type": args.type,
  26. "class": args.classname,
  27. "id": eval(args.id)
  28. }
  29. configuration=Configuration(args.name)
  30. while True:
  31. if next_module["type"]=="Chat":
  32. input_path,prompt_input_declare,prompt_path,output,next_module_temp=configuration.read_chat_config(next_module["class"],next_module["id"])
  33. prompt_input_value=configuration.input_process(input_path,prompt_input_declare)
  34. prompt=configuration.read_prompt(prompt_path)
  35. chat_module(next_module["class"],next_module["id"],prompt_input_value,prompt,output)
  36. next_module=next_module_temp
  37. elif next_module["type"]=="Judgement":
  38. input_path,judgement_input_declare,value,judgement=configuration.read_judgement_config(next_module["class"],next_module["id"])
  39. judgement_input_value=configuration.input_process(input_path,judgement_input_declare)
  40. next_module=judgment_module(judgement_input_value,value,judgement)
  41. elif next_module["type"]=="Interact":
  42. input,choices,output,next_module_temp=configuration.read_interact_config(next_module["class"],next_module["id"])
  43. choices_value=configuration.interact_input_process(input,choices)
  44. interact_module(next_module["class"],next_module["id"],choices_value,output)
  45. next_module=next_module_temp
  46. else:
  47. break