Repository: AntonOsika/gpt-engineer
File: gpt_engineer/steps.py (Python)

Code before:
from gpt_engineer.ai import AI
from gpt_engineer.chat_to_files import to_files
from gpt_engineer.db import DBs


def setup_sys_prompt(dbs):
    return (
        dbs.preprompts["generate"] + "\nUseful to know:\n" + dbs.preprompts["philosophy"]
    )


Step = TypeVar("Step", bound=Callable[[AI, DBs], List[dict]])


def simple_gen(ai: AI, dbs: DBs):
    """Run the AI on the main prompt and save the results"""
    messages = ai.start(
        setup_sys_prompt(dbs),
        dbs.input["main_prompt"],
    )
    to_files(messages[-1]["content"], dbs.workspace)
    return messages


def clarify(ai: AI, dbs: DBs):
    """
    Ask the user if they want to clarify anything and save the results to the workspace
    """
    messages = [ai.fsystem(dbs.preprompts["qa"])]
    user = dbs.input["main_prompt"]
    while True:
        messages = ai.next(messages, user)

        if messages[-1]["content"].strip().lower().startswith("no"):
            print(" Nothing more to clarify.")
            break

        print()
        user = input('(answer in text, or "c" to move on)\n')
        print()

        if not user or user == "c":
            break

        user += (
            "\n\n"
            "Is anything else unclear? If yes, only answer in the form:\n"
            "{remaining unclear areas} remaining questions.\n"
            "{Next question}\n"
            'If everything is sufficiently clear, only answer "no".'
        )

Review comment (suggestion):
Maybe something like this is a bit more readable but not a big deal (especially since this is just for the transition)

```python
def get_prompt(dbs):
    if ("main_prompt" in dbs.input) or ("prompt" not in dbs.input):
        colored("Please put your prompt in a file called `prompt` in the project directory", "red")
        
```


Or even just (not caring about `main_prompt` at all:
```python
def get_prompt(dbs):
    if "prompt" not in dbs.input:
        colored("Please put your prompt in a file called `prompt` in the project directory", "red")
        
```


Code after:
from termcolor import colored

from gpt_engineer.ai import AI
from gpt_engineer.chat_to_files import to_files
from gpt_engineer.db import DBs


def setup_sys_prompt(dbs):
    return (
        dbs.preprompts["generate"] + "\nUseful to know:\n" + dbs.preprompts["philosophy"]
    )


Step = TypeVar("Step", bound=Callable[[AI, DBs], List[dict]])


def get_prompt(dbs):
    """While we migrate we have this fallback getter"""
    assert (
        "prompt" in dbs.input or "main_prompt" in dbs.input
    ), "Please put your prompt in the file `prompt` in the project directory"

    if "prompt" not in dbs.input:
        print(
            colored("Please put the prompt in the file `prompt`, not `main_prompt", "red")
        )
        print()

    return dbs.input.get("prompt", dbs.input["main_prompt"])


def simple_gen(ai: AI, dbs: DBs):
    """Run the AI on the main prompt and save the results"""
    messages = ai.start(setup_sys_prompt(dbs), get_prompt(dbs))
    to_files(messages[-1]["content"], dbs.workspace)
    return messages


def clarify(ai: AI, dbs: DBs):
    """
    Ask the user if they want to clarify anything and save the results to the workspace
    """
    messages = [ai.fsystem(dbs.preprompts["qa"])]
    user_input = get_prompt(dbs)
    while True:
        messages = ai.next(messages, user_input)

        if messages[-1]["content"].strip().lower().startswith("no"):
            print("Nothing more to clarify.")
            break