From d1ffafcb64a2d5e117fe27dc65f10cfd6bdfa3de Mon Sep 17 00:00:00 2001 From: thinkwee Date: Thu, 21 Dec 2023 10:40:02 +0800 Subject: [PATCH] Resolve #283: fix directory not found problem when clear_structure=False --- chatdev/chat_chain.py | 15 +++++++++------ chatdev/chat_env.py | 23 +++++++++++------------ wiki.md | 10 +++++----- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/chatdev/chat_chain.py b/chatdev/chat_chain.py index ca02596e..3940757a 100644 --- a/chatdev/chat_chain.py +++ b/chatdev/chat_chain.py @@ -186,10 +186,11 @@ class ChatChain: Returns: None """ + filepath = os.path.dirname(__file__) + root = os.path.dirname(filepath) + directory = os.path.join(root, "WareHouse") + if self.chat_env.config.clear_structure: - filepath = os.path.dirname(__file__) - root = os.path.dirname(filepath) - directory = os.path.join(root, "WareHouse") for filename in os.listdir(directory): file_path = os.path.join(directory, filename) # logs with error trials are left in WareHouse/ @@ -259,8 +260,10 @@ class ChatChain: self.chat_env.codes.version += 1 os.system("cd {}; git add .".format(self.chat_env.env_dict["directory"])) log_git_info += "cd {}; git add .\n".format(self.chat_env.env_dict["directory"]) - os.system("cd {}; git commit -m \"v{} Final Version\"".format(self.chat_env.env_dict["directory"], self.chat_env.codes.version)) - log_git_info += "cd {}; git commit -m \"v{} Final Version\"\n".format(self.chat_env.env_dict["directory"], self.chat_env.codes.version) + os.system("cd {}; git commit -m \"v{} Final Version\"".format(self.chat_env.env_dict["directory"], + self.chat_env.codes.version)) + log_git_info += "cd {}; git commit -m \"v{} Final Version\"\n".format(self.chat_env.env_dict["directory"], + self.chat_env.codes.version) log_visualize(log_git_info) git_info = "**[Git Log]**\n\n" @@ -292,8 +295,8 @@ class ChatChain: post_info += "ChatDev Starts ({})".format(self.start_time) + "\n\n" post_info += "ChatDev Ends ({})".format(now_time) + "\n\n" + directory = self.chat_env.env_dict['directory'] if self.chat_env.config.clear_structure: - directory = self.chat_env.env_dict['directory'] for filename in os.listdir(directory): file_path = os.path.join(directory, filename) if os.path.isdir(file_path) and file_path.endswith("__pycache__"): diff --git a/chatdev/chat_env.py b/chatdev/chat_env.py index 97ea695a..63ab1595 100644 --- a/chatdev/chat_env.py +++ b/chatdev/chat_env.py @@ -28,10 +28,10 @@ class ChatEnvConfig: gui_design, git_management, incremental_develop): - self.clear_structure = clear_structure - self.gui_design = gui_design - self.git_management = git_management - self.incremental_develop = incremental_develop + self.clear_structure = clear_structure # Whether to clear non-software files in the WareHouse and cache files in generated software path + self.gui_design = gui_design # Encourage ChatDev generate software with GUI + self.git_management = git_management # Whether to use git to manage the creation and changes of generated software + self.incremental_develop = incremental_develop # Whether to use incremental develop on an existing project def __str__(self): string = "" @@ -81,13 +81,12 @@ class ChatEnv: new_directory = "{}.{}".format(directory, time.strftime("%Y%m%d%H%M%S", time.localtime())) shutil.copytree(directory, new_directory) print("{} Copied to {}".format(directory, new_directory)) - if self.config.clear_structure: - if os.path.exists(self.env_dict['directory']): - shutil.rmtree(self.env_dict['directory']) - os.mkdir(self.env_dict['directory']) - print("{} Created".format(directory)) - else: - os.mkdir(self.env_dict['directory']) + if os.path.exists(self.env_dict['directory']): + shutil.rmtree(self.env_dict['directory']) + os.mkdir(self.env_dict['directory']) + print("{} Created".format(directory)) + else: + os.mkdir(self.env_dict['directory']) def exist_bugs(self) -> tuple[bool, str]: directory = self.env_dict['directory'] @@ -274,7 +273,7 @@ class ChatEnv: if desc.endswith(".png"): desc = desc.replace(".png", "") print("{}: {}".format(filename, desc)) - + if openai_new_api: response = openai.images.generate( prompt=desc, diff --git a/wiki.md b/wiki.md index 7dda9be8..a7901a6c 100644 --- a/wiki.md +++ b/wiki.md @@ -271,12 +271,12 @@ then go to [Visualizer Website](http://127.0.0.1:8000/) to see an online visuali ## ChatChain Parameters -- *clear_structure*: clean cache folders. +- *clear_structure*: Whether to clear non-software files in the WareHouse and cache files in generated software path. - *brainstorming*: TBD -- *gui_design*: whether create gui for software. -- *git_management*: open git management on software project or not. -- *self_improve*: flag for self-improvement on user input prompt. It is a special chatting that LLM plays as a prompt - engineer to improve the user input prompt. **⚠️ Attention** Model generated prompts contains uncertainty and there may +- *gui_design*: Encourage ChatDev generate software with GUI. +- *git_management*: Whether to use git to manage the creation and changes of generated software. +- *incremental_develop*: Whether to use incremental develop on an existing project. +- *self_improve*: flag for self-improvement on user input prompt. It is a special chatting that LLM plays as a prompt engineer to improve the user input prompt. **⚠️ Attention** Model generated prompts contains uncertainty and there may be a deviation from the requirement meaning contained in the original prompt. - params in SimplePhase: - *max_turn_step*: Max number of chatting turn. You can increase max_turn_step for better performance but it will