From 830b5c90245231d0f870ea59d4278e0c88c9a103 Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Fri, 22 Sep 2023 23:02:43 +0200 Subject: [PATCH] Lite mode - run without pre prompts for execution (#733) * cli flag * lite mode step config * precommits * docs * pre-commits * rename function --- docs/api_reference.rst | 61 +++++++++++++++++++++++++++++++++++++++--- gpt_engineer/main.py | 11 ++++++++ gpt_engineer/steps.py | 15 ++++++++++- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/api_reference.rst b/docs/api_reference.rst index d69bbe5ca0..250dc9c4e0 100644 --- a/docs/api_reference.rst +++ b/docs/api_reference.rst @@ -23,6 +23,23 @@ Functions ai.get_tokenizer ai.serialize_messages +:mod:`gpt_engineer.api`: Api +============================= + +.. automodule:: gpt_engineer.api + :no-members: + :no-inherited-members: + +Functions +-------------- +.. currentmodule:: gpt_engineer + +.. autosummary:: + :toctree: api + + api.step_handler + api.task_handler + :mod:`gpt_engineer.chat_to_files`: Chat To Files ================================================= @@ -37,6 +54,9 @@ Functions .. autosummary:: :toctree: chat_to_files + chat_to_files.format_file_to_input + chat_to_files.get_code_strings + chat_to_files.overwrite_files chat_to_files.parse_chat chat_to_files.to_files @@ -74,6 +94,35 @@ Functions db.archive +:mod:`gpt_engineer.file_selector`: File Selector +================================================= + +.. automodule:: gpt_engineer.file_selector + :no-members: + :no-inherited-members: + +Classes +-------------- +.. currentmodule:: gpt_engineer + +.. autosummary:: + :toctree: file_selector + :template: class.rst + + file_selector.DisplayablePath + +Functions +-------------- +.. currentmodule:: gpt_engineer + +.. autosummary:: + :toctree: file_selector + + file_selector.ask_for_files + file_selector.gui_file_selector + file_selector.is_in_ignoring_extensions + file_selector.terminal_file_selector + :mod:`gpt_engineer.learning`: Learning ======================================= @@ -93,7 +142,7 @@ Functions learning.collect_consent learning.extract_learning learning.get_session - learning.human_input + learning.human_review_input learning.logs_to_string :mod:`gpt_engineer.main`: Main @@ -110,6 +159,7 @@ Functions .. autosummary:: :toctree: main + main.load_env_if_needed main.main :mod:`gpt_engineer.steps`: Steps @@ -136,18 +186,23 @@ Functions .. autosummary:: :toctree: steps + steps.assert_files_ready steps.clarify steps.curr_fn steps.execute_entrypoint steps.fix_code steps.gen_clarified_code - steps.gen_code + steps.gen_code_after_unit_tests steps.gen_entrypoint steps.gen_spec steps.gen_unit_tests - steps.get_prompt + steps.get_improve_prompt steps.human_review + steps.improve_existing_code + steps.lite_gen steps.respec + steps.set_improve_filelist steps.setup_sys_prompt + steps.setup_sys_prompt_existing_code steps.simple_gen steps.use_feedback diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index c4b8b8c062..1daa93dd73 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -37,6 +37,12 @@ def main( "-i", help="Improve code from existing project.", ), + lite_mode: bool = typer.Option( + False, + "--lite", + "-l", + help="Lite mode - run only the main prompt.", + ), azure_endpoint: str = typer.Option( "", "--azure", @@ -48,6 +54,11 @@ def main( ): logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) + if lite_mode: + assert not improve_option, "Lite mode cannot improve code" + if steps_config == StepsConfig.DEFAULT: + steps_config = StepsConfig.LITE + # For the improve option take current project as path and add .gpteng folder if improve_option: # The default option for the --improve is the IMPROVE_CODE, not DEFAULT diff --git a/gpt_engineer/steps.py b/gpt_engineer/steps.py index c302a3b7d7..f8bfa70de8 100644 --- a/gpt_engineer/steps.py +++ b/gpt_engineer/steps.py @@ -60,8 +60,17 @@ def curr_fn() -> str: # All steps below have the Step signature +def lite_gen(ai: AI, dbs: DBs) -> List[Message]: + """Run the AI on only the main prompt and save the results""" + messages = ai.start( + dbs.input["prompt"], dbs.preprompts["file_format"], step_name=curr_fn() + ) + to_files(messages[-1].content.strip(), dbs.workspace) + return messages + + def simple_gen(ai: AI, dbs: DBs) -> List[Message]: - """Run the AI on the main prompt and save the results""" + """Run the AI on the default prompts and save the results""" messages = ai.start(setup_sys_prompt(dbs), dbs.input["prompt"], step_name=curr_fn()) to_files(messages[-1].content.strip(), dbs.workspace) return messages @@ -393,6 +402,7 @@ class Config(str, Enum): DEFAULT = "default" BENCHMARK = "benchmark" SIMPLE = "simple" + LITE = "lite" TDD = "tdd" TDD_PLUS = "tdd+" CLARIFY = "clarify" @@ -413,6 +423,9 @@ class Config(str, Enum): execute_entrypoint, human_review, ], + Config.LITE: [ + lite_gen, + ], Config.BENCHMARK: [ simple_gen, gen_entrypoint,