Resolve #283: fix directory not found problem when clear_structure=False

This commit is contained in:
thinkwee 2023-12-21 10:40:02 +08:00
parent 452df57cca
commit d1ffafcb64
3 changed files with 25 additions and 23 deletions

View File

@ -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__"):

View File

@ -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,

10
wiki.md
View File

@ -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