Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs quick overview #988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/DOCS_BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ python create_api_rst.py

# Build the docs
make html

## Alternatively, to rebuild the docs on changes with live-reload in the browser
sphinx-autobuild docs _build/html
```

Project Docs Structure
Expand Down
68 changes: 36 additions & 32 deletions docs/intro/quick_overview.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
# GPT-Engineer Documentation

GPT-Engineer is a project that uses GPT-4 to automate the process of software engineering. It includes several Python scripts that interact with the GPT-4 model to generate code, clarify requirements, generate specifications, and more.
GPT-Engineer is a project that uses LLMs (such as GPT-4) to automate the process of software engineering. It includes several Python scripts that interact with the LLM to generate code, clarify requirements, generate specifications, and more.

<br>

## Core Components
### 1. AI Class (`gpt_engineer/ai.py`)
The AI class is the main interface to the GPT-4 model. It provides methods to start a conversation with the model, continue an existing conversation, and format system and user messages.

(ai_class)=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this some markdown extension I'm not aware of? Never seen before 😮

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me neither! Apparently, its Sphinx way of doing cross-references in the MyST Markdown dialect (see docs).

### 1. AI Class (`gpt_engineer/core/ai.py`)
The `AI` class is the main interface to the LLM. It provides methods to start a conversation with the model, continue an existing conversation, and format system and user messages.

<br>

### 2. Chat to Files (`gpt_engineer/chat_to_files.py`)
This module contains two main functions:
(agent_class)=
### 2. Agent Class (`gpt_engineer/applications/cli/cli_agent.py`)
The `Agent` class is responsible for managing the lifecycle of code generation and improvement. Its main functions are:

`parse_chat(chat)`: This function takes a chat conversation and extracts all the code blocks and preceding filenames. It returns a list of tuples, where each tuple contains a filename and the corresponding code block.
- `init(self, prompt)`: Generates a new piece of code using the AI based on the provided prompt. It also generates a entrypoint file based on the generated code.

`to_files_and_memory(chat, dbs)`: This function takes the chat and the DBs as arguments. DBs contains the workspace and memory path. The function first saves the entire chat as a text file in the memory path. Then it calls the to_files function to write each file to the workspace.
- `improve(self, files_dict, prompt)`: Improves an existing piece of code using the AI class based on the provided prompt and files dictionary.

`to_files(chat, db)`: This function takes the chat and workspace DB as arguments. It calls the parse_chat function to parse the chat and get the files. Each file is then saved to the workspace.
<br>

(files_dictionary_class)=
### 3. Files Dictionary Class (`gpt_engineer/core/files_dict.py`)
The `Files Dictionary` class extends the standard dictionary to enforce string keys and values, representing filenames and their corresponding code content. It provides a method to format its contents for chat-based interaction with the `AI` class.

<br>

### 3. DB Class (`gpt_engineer/db.py`)
The DB class represents a simple database that stores its data as files in a directory. It provides methods to check if a key (filename) exists in the database, get the value (file content) associated with a key, and set the value associated with a key.
### 4. Chat to Files (`gpt_engineer/core/chat_to_files.py`)
This module provides utilities to handle and process chat content, including parsing chat messages to retrieve code blocks, storing these blocks in the [`Files Dictionary`](files_dictionary_class), and overwriting the files based on new chat messages. The module contains four main functions:

The DBs class is a dataclass that contains instances of the DB class for different types of data (memory, logs, input, workspace, and preprompts).
- `chat_to_files_dict(chat)`: This function takes a chat conversation and extracts all the code blocks and preceding filenames. It returns an instance of [`Files Dictionary`](files_dictionary_class) representing filenames and their corresponding code content.

<br>
- `parse_edits(chat)`: This function parses edits from a chat and returns them as a list of `Edit` class objects.

### 4. Main Script (`gpt_engineer/main.py`)
The main script uses the `Typer` library to create a command-line interface. It sets up the AI model and the databases, and then runs a series of steps based on the provided configuration.
- `apply_edits(edits, files_dict)`: This function takes a list of Edit objects and applies each edit to the code object. It handles the creation of new files and the modification of existing files when required.

- `overwrite_code_with_edits(chat, files_dict)`: This function takes a chat string, and employs the `parse_edits` function to parse it for edits, before applying the edits to the relevant code object via the `apply_edits` function.

<br>

### 5. Steps (`gpt_engineer/steps.py`)
This module defines a series of steps that can be run in the main script. Each step is a function that takes an instance of the AI class and an instance of the DBs class, and returns a list of messages.
(steps)=
### 5. Steps (`gpt_engineer/core/default/steps.py`)
This module defines a series of steps that can be run by the agent.
The main steps are:

- `gen_code(ai, prompt, memory, preprompts_holder)`: Generate new code based on the specification.

- `gen_entrypoint(ai, files_dict, memory, preprompts_holder)`: Generate an entrypoint file code based on the generated code.

- `execute_entrypoint(ai, execution_env, files_dict, preprompts_holder)`: Uses the entrypoint file to run the generated code inside the execution environment.

- `improve(ai, prompt, files_dict, memory, preprompts_holder)`: Improves an existing codebase based on the provided specifications.

<br>

The steps include:

`simple_gen(ai, dbs)`: Run the AI on the main prompt and save the results. <br>
`clarify(ai, dbs)`: Ask the user if they want to clarify anything and save the results to the workspace. <br>
`gen_spec(ai, dbs)`: Generate a spec from the main prompt + clarifications and save the results to the workspace. <br>
`respec(ai, dbs)`: Ask the AI to reiterate the specification and save the results to the workspace. <br>
`gen_unit_tests(ai, dbs)`: Generate unit tests based on the specification. <br>
`gen_clarified_code(ai, dbs)`: Generate code based on the main prompt and clarifications. <br>
`gen_code(ai, dbs)`: Generate code based on the specification and unit tests. <br>
`execute_entrypoint(ai, dbs)`: Execute the entrypoint script in the workspace. <br>
`gen_entrypoint(ai, dbs)`: Generate an entrypoint script based on the code in the workspace. <br>
`use_feedback(ai, dbs)`: Ask the AI to generate code based on feedback. <br>
`fix_code(ai, dbs)`: Ask the AI to fix any errors in the code. <br>

The steps are grouped into different configurations (default, benchmark, simple, tdd, tdd+, clarify, respec, execute_only, use_feedback), which can be selected when running the main script.
### 6. Main Script (`gpt_engineer/applications/cli/main.py`)
The main script is the is the entry point of the application and uses the `Typer` library to create a command-line interface. It sets up instances of an [`AI`](ai_class), a [`Files Dictionary`](files_dictionary_class), a `BaseMemory`, a `BaseExecutionEnv` and an [`Agent`](agent_class) that runs a series of [steps](steps) based on the provided configuration.
Loading