Merge pull request #246 from wyifei26/main

feat: Add incremental development.
This commit is contained in:
Chen Qian 2023-11-02 15:58:35 +08:00 committed by GitHub
commit c9f6ad3d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 130 additions and 9 deletions

View File

@ -116,5 +116,6 @@
"brainstorming": "False",
"gui_design": "True",
"git_management": "False",
"self_improve": "False"
"self_improve": "False",
"incremental_develop": "False"
}

View File

@ -110,5 +110,6 @@
"brainstorming": "False",
"gui_design": "True",
"git_management": "False",
"self_improve": "False"
"self_improve": "False",
"incremental_develop": "False"
}

View File

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

View File

@ -26,7 +26,9 @@
## 🎉 News
* **October 26th, 2023: ChatDev is now supported with Docker for safe execution** (thanks to contribution from [ManindraDeMel](https://github.com/ManindraDeMel)). Please see [Docker Start Guide](wiki.md#docker-start).
* **November 2nd, 2023: ChatDev is now supported with incremental development.** Try `--config "incremental" --path "Your folder path"` to start it. This mode will start with code review phase base on the existing codes.
* October 26th, 2023: ChatDev is now supported with Docker for safe execution (thanks to contribution from [ManindraDeMel](https://github.com/ManindraDeMel)). Please see [Docker Start Guide](wiki.md#docker-start).
<p align="center">
<img src='./misc/docker.png' width=400>
</p>

View File

@ -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,19 @@ 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
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, 'base', relative_path)
os.makedirs(target_dir, exist_ok=True)
for file in files:
source_file = os.path.join(root, file)
target_file = os.path.join(target_dir, file)
shutil.copy2(source_file, target_file)
self.chat_env._load_from_hardware(os.path.join(software_path, 'base'))
# 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)
@ -251,7 +266,7 @@ class ChatChain:
git_info = "**[Git Log]**\n\n"
import subprocess
# 执行git log命令
# execute git log
command = "cd {}; git log".format(self.chat_env.env_dict["directory"])
completed_process = subprocess.run(command, shell=True, text=True, stdout=subprocess.PIPE)

View File

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

5
run.py
View File

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