fixes for storing dev steps and command runs to db

pull/1160/head
LeonOstrez 3 years ago
parent 5c7efa0261
commit c1aaff6b2c

@ -290,10 +290,9 @@ def save_development_step(project, prompt_path, prompt_data, messages, llm_respo
development_step = hash_and_save_step(DevelopmentSteps, project.args['app_id'], unique_data, data_fields,
"Saved Development Step")
if development_step is not None:
project.checkpoints['last_development_step'] = development_step
project.checkpoints['last_development_step'] = development_step
project.save_files_snapshot(development_step.id)
project.save_files_snapshot(development_step.id)
return development_step
@ -304,7 +303,7 @@ def get_saved_development_step(project):
return development_step
def save_command_run(project, command, cli_response):
def save_command_run(project, command, cli_response, done_or_error_response, exit_code):
if project.current_step != 'coding':
return
@ -317,6 +316,8 @@ def save_command_run(project, command, cli_response):
data_fields = {
'command': command,
'cli_response': cli_response,
'done_or_error_response': done_or_error_response,
'exit_code': exit_code,
}
command_run = hash_and_save_step(CommandRuns, project.args['app_id'], unique_data, data_fields, "Saved Command Run")

@ -1,4 +1,4 @@
from peewee import AutoField, ForeignKeyField, TextField, CharField
from peewee import AutoField, ForeignKeyField, TextField, CharField, IntegerField
from database.models.components.base_models import BaseModel
from database.models.app import App
@ -9,6 +9,8 @@ class CommandRuns(BaseModel):
app = ForeignKeyField(App, on_delete='CASCADE')
command = TextField(null=True)
cli_response = TextField(null=True)
done_or_error_response = TextField(null=True)
exit_code = IntegerField(null=True)
previous_step = ForeignKeyField('self', null=True, column_name='previous_step')
high_level_step = CharField(null=True)

@ -141,6 +141,14 @@ def execute_command(project, command, timeout=None, success_message=None, comman
timeout = min(max(timeout, MIN_COMMAND_RUN_TIME), MAX_COMMAND_RUN_TIME)
project.command_runs_count += 1
command_run = get_saved_command_run(project, command)
if command_run is not None and project.skip_steps:
# if we do, use it
project.checkpoints['last_command_run'] = command_run
print(color_yellow(f'Restoring command run response id {command_run.id}:\n```\n{command_run.cli_response}```'))
return command_run.cli_response, command_run.done_or_error_response, command_run.exit_code
if not force:
print(color_yellow_bold('\n--------- EXECUTE COMMAND ----------'))
question = f'Can I execute the command: `{color_yellow_bold(command)}`'
@ -153,26 +161,20 @@ def execute_command(project, command, timeout=None, success_message=None, comman
# TODO can we use .confirm(question, default='yes').ask() https://questionary.readthedocs.io/en/stable/pages/types.html#confirmation
print('answer: ' + answer)
if answer.lower() in ['no', 'skip']:
save_command_run(project, command, None, 'DONE', None)
return None, 'DONE', None
elif answer.lower() not in ['', 'yes', 'ok', 'okay', 'sure']:
# "That's not going to work, let's do X instead"
# https://github.com/Pythagora-io/gpt-pilot/issues/198
# https://github.com/Pythagora-io/gpt-pilot/issues/43#issuecomment-1756352056
# TODO: https://github.com/Pythagora-io/gpt-pilot/issues/122
save_command_run(project, command, None, answer, None)
return None, answer, None
# TODO when a shell built-in commands (like cd or source) is executed, the output is not captured properly - this will need to be changed at some point
if platform.system() != 'Windows' and ("cd " in command or "source " in command):
command = "bash -c '" + command + "'"
project.command_runs_count += 1
command_run = get_saved_command_run(project, command)
if command_run is not None and project.skip_steps:
# if we do, use it
project.checkpoints['last_command_run'] = command_run
print(color_yellow(f'Restoring command run response id {command_run.id}:\n```\n{command_run.cli_response}```'))
return command_run.cli_response, None, None
return_value = None
done_or_error_response = None
@ -284,7 +286,7 @@ def execute_command(project, command, timeout=None, success_message=None, comman
return_value = 'stderr:\n```\n' + stderr_output[0:MAX_COMMAND_OUTPUT_LENGTH] + '\n```\n'
return_value += 'stdout:\n```\n' + output[-MAX_COMMAND_OUTPUT_LENGTH:] + '\n```'
save_command_run(project, command, return_value)
save_command_run(project, command, return_value, done_or_error_response, process.returncode)
return return_value, done_or_error_response, process.returncode

@ -37,7 +37,7 @@ def styled_text(project, question, ignore_user_input_count=False, style=None):
print(response)
if not ignore_user_input_count:
user_input = save_user_input(project, question, response)
save_user_input(project, question, response)
print('\n\n', end='')
return response

Loading…
Cancel
Save