mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
add execute step
This commit is contained in:
@@ -6,43 +6,43 @@ from gpt_engineer.db import DBs
|
|||||||
|
|
||||||
|
|
||||||
def setup_sys_prompt(dbs):
|
def setup_sys_prompt(dbs):
|
||||||
return dbs.identity['setup'] + '\nUseful to know:\n' + dbs.identity['philosophy']
|
return dbs.identity["setup"] + "\nUseful to know:\n" + dbs.identity["philosophy"]
|
||||||
|
|
||||||
|
|
||||||
def run(ai: AI, dbs: DBs):
|
def run(ai: AI, dbs: DBs):
|
||||||
'''Run the AI on the main prompt and save the results'''
|
"""Run the AI on the main prompt and save the results"""
|
||||||
messages = ai.start(
|
messages = ai.start(
|
||||||
setup_sys_prompt(dbs),
|
setup_sys_prompt(dbs),
|
||||||
dbs.input['main_prompt'],
|
dbs.input["main_prompt"],
|
||||||
)
|
)
|
||||||
to_files(messages[-1]['content'], dbs.workspace)
|
to_files(messages[-1]["content"], dbs.workspace)
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
def clarify(ai: AI, dbs: DBs):
|
def clarify(ai: AI, dbs: DBs):
|
||||||
'''
|
"""
|
||||||
Ask the user if they want to clarify anything and save the results to the workspace
|
Ask the user if they want to clarify anything and save the results to the workspace
|
||||||
'''
|
"""
|
||||||
messages = [ai.fsystem(dbs.identity['qa'])]
|
messages = [ai.fsystem(dbs.identity["qa"])]
|
||||||
user = dbs.input['main_prompt']
|
user = dbs.input["main_prompt"]
|
||||||
while True:
|
while True:
|
||||||
messages = ai.next(messages, user)
|
messages = ai.next(messages, user)
|
||||||
|
|
||||||
if messages[-1]['content'].strip().lower() == 'no':
|
if messages[-1]["content"].strip().lower() == "no":
|
||||||
break
|
break
|
||||||
|
|
||||||
print()
|
print()
|
||||||
user = input('(answer in text, or "q" to move on)\n')
|
user = input('(answer in text, or "q" to move on)\n')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if not user or user == 'q':
|
if not user or user == "q":
|
||||||
break
|
break
|
||||||
|
|
||||||
user += (
|
user += (
|
||||||
'\n\n'
|
"\n\n"
|
||||||
'Is anything else unclear? If yes, only answer in the form:\n'
|
"Is anything else unclear? If yes, only answer in the form:\n"
|
||||||
'{remaining unclear areas} remaining questions.\n'
|
"{remaining unclear areas} remaining questions.\n"
|
||||||
'{Next question}\n'
|
"{Next question}\n"
|
||||||
'If everything is sufficiently clear, only answer "no".'
|
'If everything is sufficiently clear, only answer "no".'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,14 +87,39 @@ def run_clarified(ai: AI, dbs: DBs):
|
|||||||
ai.fuser(f"Specification:\n\n{dbs.memory['specification']}"),
|
ai.fuser(f"Specification:\n\n{dbs.memory['specification']}"),
|
||||||
ai.fuser(f"Unit tests:\n\n{dbs.memory['unit_tests']}"),
|
ai.fuser(f"Unit tests:\n\n{dbs.memory['unit_tests']}"),
|
||||||
]
|
]
|
||||||
messages = ai.next(messages, dbs.identity['use_qa'])
|
messages = ai.next(messages, dbs.identity["use_qa"])
|
||||||
to_files(messages[-1]['content'], dbs.workspace)
|
to_files(messages[-1]["content"], dbs.workspace)
|
||||||
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
def execute_workspace(ai: AI, dbs: DBs):
|
||||||
|
messages = ai.start(
|
||||||
|
system=(
|
||||||
|
f"You will get infomation about a codebase that is currently on disk in the folder {dbs.workspace.path}.\n"
|
||||||
|
"From this you will answer with one code block that includes all the necessary macos terminal commands to "
|
||||||
|
"a) install dependencies "
|
||||||
|
"b) run the necessary parts of the codebase to try it."
|
||||||
|
),
|
||||||
|
user="Information about the codebase:\n\n" + dbs.workspace["all_output.txt"],
|
||||||
|
)
|
||||||
|
command = messages[-1]['content'].strip('```')
|
||||||
|
print('Do you want to execute this code?')
|
||||||
|
print(command)
|
||||||
|
print()
|
||||||
|
print('If yes, press enter. If no, type "no"')
|
||||||
|
print()
|
||||||
|
if input() == 'no':
|
||||||
|
print('Ok, not executing the code.')
|
||||||
|
return messages
|
||||||
|
print('Executing the code...')
|
||||||
|
print()
|
||||||
|
subprocess.run(command, shell=True)
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
# Different configs of what steps to run
|
# Different configs of what steps to run
|
||||||
STEPS = {
|
STEPS = {
|
||||||
'default': [run],
|
"default": [run, execute_workspace],
|
||||||
'unit_tests': [gen_spec, pre_unit_tests, run_clarified],
|
'unit_tests': [gen_spec, pre_unit_tests, run_clarified],
|
||||||
'clarify': [clarify, run_clarified],
|
'clarify': [clarify, run_clarified],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user