gpt-engineer icon indicating copy to clipboard operation
gpt-engineer copied to clipboard

feat: :fire: add guidance client

Open ekusiadadus opened this issue 1 year ago • 2 comments

why

  • [x] add MS guidance as a alternative for Class AI

Can be used as following main.py

import json
import logging
import shutil

from pathlib import Path

import typer

from gpt_engineer import steps
from gpt_engineer.ai_with_guidance import AIwithGuidance
from gpt_engineer.db import DB, DBs
from gpt_engineer.steps import STEPS

app = typer.Typer()


@app.command()
def main(
    project_path: str = typer.Argument("example", help="path"),
    delete_existing: bool = typer.Argument(False, help="delete existing files"),
    model: str = "gpt-4",
    temperature: float = 0.1,
    steps_config: steps.Config = typer.Option(
        steps.Config.DEFAULT, "--steps", "-s", help="decide which steps to run"
    ),
    verbose: bool = typer.Option(False, "--verbose", "-v"),
    run_prefix: str = typer.Option(
        "",
        help=(
            "run prefix, if you want to run multiple variants of the same project and "
            "later compare them"
        ),
    ),
):
    logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO)

    input_path = Path(project_path).absolute()
    memory_path = input_path / f"{run_prefix}memory"
    workspace_path = input_path / f"{run_prefix}workspace"

    if delete_existing:
        # Delete files and subdirectories in paths
        shutil.rmtree(memory_path, ignore_errors=True)
        shutil.rmtree(workspace_path, ignore_errors=True)

    ai = AIwithGuidance(
        model=model,
        temperature=temperature,
    )

    dbs = DBs(
        memory=DB(memory_path),
        logs=DB(memory_path / "logs"),
        input=DB(input_path),
        workspace=DB(workspace_path),
        preprompts=DB(Path(__file__).parent / "preprompts"),
    )

    for step in STEPS[steps_config]:
        messages = step(ai, dbs)
        dbs.logs[step.__name__] = json.dumps(messages)


if __name__ == "__main__":
    app()

ekusiadadus avatar Jun 23 '23 11:06 ekusiadadus

Thanks for the contribution!

I would probably make it inherit much of the functionality from the AI class. Also this change doesn't seem to actually add any functionality, just use a different library?

FOLLGAD avatar Jun 23 '23 12:06 FOLLGAD

@FOLLGAD

Thank you for your feedback!

This Pull Request (PR) is primarily aimed at introducing the Guidance Client, and as such, does not include any additional functionality. However, I'd like to emphasize that the new AIwithGuidance class will maintain equivalent functionality to the current AI class, with the addition of guidance-specific enhancements.

I understand the importance of leveraging existing code. Therefore, my plan is to have AIwithGuidance inherit most of its functionalities from the AI class.

ekusiadadus avatar Jun 23 '23 12:06 ekusiadadus

Thanks for wanting to contribute! There are many ways.

But what problem does this solve?

To merge, we would need it to actually use functionality in guidance and have a "case" for this being better

We want as few lines of code as possible.

AntonOsika avatar Jun 23 '23 21:06 AntonOsika

@AntonOsika

Thank you for your feedback! I had thought of this PR as I saw using guidance in the benchmarks on the roadmap. However, as you correctly pointed out, my current implementation doesn't introduce any new functionality. It also seems to go against the policy of preferring fewer lines of code.

Therefore, I've decided to close this PR. I'll make another PR when I have another opportunity.

ekusiadadus avatar Jun 24 '23 01:06 ekusiadadus