From 5cb6b4539b34c5704b491785b25fe17de471db0d Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Sat, 17 Jun 2023 14:10:29 +0200 Subject: [PATCH] Execute step --- gpt_engineer/chat_to_files.py | 6 ++++-- gpt_engineer/steps.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gpt_engineer/chat_to_files.py b/gpt_engineer/chat_to_files.py index 890ba33..9c8a9e6 100644 --- a/gpt_engineer/chat_to_files.py +++ b/gpt_engineer/chat_to_files.py @@ -1,7 +1,9 @@ import re +from typing import List, Tuple +from gpt_engineer.db import DB -def parse_chat(chat): # -> List[Tuple[str, str]]: +def parse_chat(chat) -> List[Tuple[str, str]]: # Get all ``` blocks regex = r"```(.*?)```" @@ -19,7 +21,7 @@ def parse_chat(chat): # -> List[Tuple[str, str]]: return files -def to_files(chat, workspace): +def to_files(chat: str, workspace: DB): workspace["all_output.txt"] = chat files = parse_chat(chat) diff --git a/gpt_engineer/steps.py b/gpt_engineer/steps.py index ec3e5c3..52ab0ec 100644 --- a/gpt_engineer/steps.py +++ b/gpt_engineer/steps.py @@ -1,8 +1,10 @@ import json +import subprocess from gpt_engineer.ai import AI from gpt_engineer.chat_to_files import to_files from gpt_engineer.db import DBs +from gpt_engineer.chat_to_files import parse_chat def setup_sys_prompt(dbs): @@ -98,11 +100,15 @@ def execute_workspace(ai: AI, dbs: DBs): 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." + "b) run the necessary parts of the codebase to try it.\n" + "Do not explain the code, just give the commands.\n" ), user="Information about the codebase:\n\n" + dbs.workspace["all_output.txt"], ) - command = messages[-1]['content'].strip('```') + + [[lang, command]] = parse_chat(messages[-1]['content']) + assert lang in ['', 'bash'] + print('Do you want to execute this code?') print(command) print() @@ -125,7 +131,7 @@ STEPS = { } # Future steps that can be added: -# improve_files, +# self_reflect_and_improve_files, # add_tests # run_tests_and_fix_files, # improve_based_on_in_file_feedback_comments