From 1dfb0610c3e1f60bb76382034078cb20bb90780c Mon Sep 17 00:00:00 2001 From: wyifei26 Date: Fri, 27 Oct 2023 15:52:57 +0800 Subject: [PATCH] feat: Initialize incremental develop mode. --- .../Incremental/ChatChainConfig.json | 96 +++++++++++++++++++ chatdev/chat_chain.py | 26 ++++- chatdev/chat_env.py | 10 +- run.py | 5 +- 4 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 CompanyConfig/Incremental/ChatChainConfig.json diff --git a/CompanyConfig/Incremental/ChatChainConfig.json b/CompanyConfig/Incremental/ChatChainConfig.json new file mode 100644 index 00000000..5dfe1398 --- /dev/null +++ b/CompanyConfig/Incremental/ChatChainConfig.json @@ -0,0 +1,96 @@ +{ + "chain": [ + { + "phase": "DemandAnalysis", + "phaseType": "SimplePhase", + "max_turn_step": -1, + "need_reflect": "True" + }, + { + "phase": "LanguageChoose", + "phaseType": "SimplePhase", + "max_turn_step": -1, + "need_reflect": "True" + }, + { + "phase": "CodeCompleteAll", + "phaseType": "ComposedPhase", + "cycleNum": 10, + "Composition": [ + { + "phase": "CodeComplete", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + } + ] + }, + { + "phase": "CodeReview", + "phaseType": "ComposedPhase", + "cycleNum": 3, + "Composition": [ + { + "phase": "CodeReviewComment", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + }, + { + "phase": "CodeReviewModification", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + } + ] + }, + { + "phase": "Test", + "phaseType": "ComposedPhase", + "cycleNum": 3, + "Composition": [ + { + "phase": "TestErrorSummary", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + }, + { + "phase": "TestModification", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + } + ] + }, + { + "phase": "EnvironmentDoc", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "True" + }, + { + "phase": "Manual", + "phaseType": "SimplePhase", + "max_turn_step": 1, + "need_reflect": "False" + } + ], + "recruitments": [ + "Chief Executive Officer", + "Counselor", + "Chief Human Resource Officer", + "Chief Product Officer", + "Chief Technology Officer", + "Programmer", + "Code Reviewer", + "Software Test Engineer", + "Chief Creative Officer" + ], + "clear_structure": "True", + "brainstorming": "False", + "gui_design": "True", + "git_management": "False", + "self_improve": "False", + "incremental_develop": "True" +} diff --git a/chatdev/chat_chain.py b/chatdev/chat_chain.py index 5a50652d..27ed1f33 100644 --- a/chatdev/chat_chain.py +++ b/chatdev/chat_chain.py @@ -27,7 +27,8 @@ class ChatChain: task_prompt: str = None, project_name: str = None, org_name: str = None, - model_type: ModelType = ModelType.GPT_3_5_TURBO) -> None: + model_type: ModelType = ModelType.GPT_3_5_TURBO, + code_path: str = None) -> None: """ Args: @@ -46,6 +47,7 @@ class ChatChain: self.project_name = project_name self.org_name = org_name self.model_type = model_type + self.code_path = code_path with open(self.config_path, 'r', encoding="utf8") as file: self.config = json.load(file) @@ -64,7 +66,8 @@ class ChatChain: # init ChatEnv self.chat_env_config = ChatEnvConfig(clear_structure=check_bool(self.config["clear_structure"]), gui_design=check_bool(self.config["gui_design"]), - git_management=check_bool(self.config["git_management"])) + git_management=check_bool(self.config["git_management"]), + incremental_develop=check_bool(self.config["incremental_develop"])) self.chat_env = ChatEnv(self.chat_env_config) # the user input prompt will be self-improved (if set "self_improve": "True" in ChatChainConfig.json) @@ -202,7 +205,24 @@ class ChatChain: shutil.copy(self.config_phase_path, software_path) shutil.copy(self.config_role_path, software_path) - # write task prompt to software path + # copy code files to software path in incremental_develop mode + ignore_files = ['ChatChainConfig.json', + 'PhaseConfig.json', + 'RoleConfig.json', + 'manual.md', + 'meta.txt'] + if check_bool(self.config["incremental_develop"]): + for root, dirs, files in os.walk(self.code_path): + relative_path = os.path.relpath(root, self.code_path) + target_dir = os.path.join(software_path, relative_path) + os.makedirs(target_dir, exist_ok=True) + for file in files: + if file not in ignore_files: + source_file = os.path.join(root, file) + target_file = os.path.join(target_dir, file) + shutil.copy2(source_file, target_file) + + # write task prompt to software with open(os.path.join(software_path, self.project_name + ".prompt"), "w") as f: f.write(self.task_prompt_raw) diff --git a/chatdev/chat_env.py b/chatdev/chat_env.py index a986310d..16a8a9ca 100644 --- a/chatdev/chat_env.py +++ b/chatdev/chat_env.py @@ -18,16 +18,19 @@ from chatdev.utils import log_and_print_online class ChatEnvConfig: def __init__(self, clear_structure, gui_design, - git_management): + git_management, + incremental_develop): self.clear_structure = clear_structure self.gui_design = gui_design self.git_management = git_management + self.incremental_develop = incremental_develop def __str__(self): string = "" string += "ChatEnvConfig.clear_structure: {}\n".format(self.clear_structure) string += "ChatEnvConfig.git_management: {}\n".format(self.git_management) string += "ChatEnvConfig.gui_design: {}\n".format(self.gui_design) + string += "ChatEnvConfig.incremental_develop: {}\n".format(self.incremental_develop) return string @@ -35,7 +38,10 @@ class ChatEnv: def __init__(self, chat_env_config: ChatEnvConfig): self.config = chat_env_config self.roster: Roster = Roster() - self.codes: Codes = Codes() + if chat_env_config.incremental_develop: + self.codes: Codes = Codes(generated_content="") + else: + self.codes: Codes = Codes() self.proposed_images: Dict[str, str] = {} self.incorporated_images: Dict[str, str] = {} self.requirements: Documents = Documents() diff --git a/run.py b/run.py index 6b152803..b92139d6 100644 --- a/run.py +++ b/run.py @@ -68,6 +68,8 @@ parser.add_argument('--name', type=str, default="Gomoku", help="Name of software, your software will be generated in WareHouse/name_org_timestamp") parser.add_argument('--model', type=str, default="GPT_3_5_TURBO", help="GPT Model, choose from {'GPT_3_5_TURBO','GPT_4','GPT_4_32K'}") +parser.add_argument('--path', type=str, default="", + help="Your file directory, ChatDev will build upon your software in the Incremental mode") args = parser.parse_args() # Start ChatDev @@ -83,7 +85,8 @@ chat_chain = ChatChain(config_path=config_path, task_prompt=args.task, project_name=args.name, org_name=args.org, - model_type=args2type[args.model]) + model_type=args2type[args.model], + code_path=args.path) # ---------------------------------------- # Init Log