feat: Initialize incremental develop mode.

This commit is contained in:
wyifei26 2023-10-27 15:52:57 +08:00
parent e74e8d7987
commit 1dfb0610c3
4 changed files with 131 additions and 6 deletions

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

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

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

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