In the ever-evolving landscape of software development, the fusion of artificial intelligence and programming has opened up new horizons. Today, we’re going to explore one such marvel: GPT Engineer, a Python-based application that leverages OpenAI’s services to generate code.
GPT Engineer is not just a code generator; it’s a testament to the potential of AI in software development.

From generating entry points to executing them, from supporting Test-Driven Development to clarifying specifications, GPT Engineer is a comprehensive tool that encapsulates various aspects of software development.
Join us as we delve into:
- the intricacies of GPT Engineer
- exploring its modular approach
- its support for different workflows, and
- its commitment to quality and performance

Whether you’re a seasoned developer or a curious enthusiast, prepare to be amazed by the fusion of AI and coding in GPT Engineer.
Project Organization and Structure
The application follows a modular approach, with different functionalities encapsulated in separate methods. These methods are then combined in various configurations to perform different tasks.
Here’s a high-level overview of the application:
Entry Point Generation and Execution
The application includes methods for generating and executing entry points.

These methods are used in almost all configurations, serving as the starting and ending points of the application’s operation.
Test-Driven Development (TDD)
The application supports TDD, with methods for generating specifications, unit tests, and code.

There’s also a method for fixing the code based on the tests.
Specification Clarification
The application includes a method for clarifying specifications, which generates clarified code based on the clarified specifications.
Feedback Utilization
The application can utilize feedback to improve its operation, with a method dedicated to this purpose.
Code Execution
The application includes a configuration that only executes the entry point, without performing any other operations.

The repository also includes guidelines for:
- contributing to the project
- a code of conduct, and
- a list of benchmarks for testing the application’s performance.
It also contains a detailed explanation of a Git workflow that safeguards topic branches from being rewound.
How It Works: Using Open AI via Python
The GPT Engineer application interacts with OpenAI using a class named AI
.

Here are some key snippets from the code base that demonstrate this interaction:
import openai
class AI:
def __init__(self, model="gpt-4", temperature=0.1):
self.temperature = temperature
try:
openai.Model.retrieve(model)
self.model = model
except openai.InvalidRequestError:
print(
f"Model {model} not available for provided API key. Reverting "
"to gpt-3.5-turbo. Sign up for the GPT-4 wait list here: "
"https://openai.com/waitlist/gpt-4-api"
)
self.model = "gpt-3.5-turbo"
In the AI
class’s __init__
method, it first tries to retrieve the specified model from OpenAI.

If the model is not available, it defaults to “gpt-3.5-turbo”.
def start(self, system, user):
messages = [
{"role": "system", "content": system},
{"role": "user", "content": user},
]
return self.next(messages)
The start
method initializes a conversation with the AI model. It takes two arguments: system
and user
, which represent the system’s and user’s initial messages, respectively.

The simple_gen
function uses the start
method of the AI
class to run the AI on the main prompt and save the results.
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
These snippets demonstrate how the GPT Engineer application interacts with OpenAI’s API to generate code.

The application uses the OpenAI API to generate responses to prompts, which are then processed and used to generate code.
Let’s Make It Work For Us: Create Your First App with a Prompt
In this section, we’ll walk through the steps to create a simple app using GPT Engineer.

Our app will be a basic “Weather Reporter” that fetches weather data for a given location. This is a simple yet practical example that will help you understand how to use GPT Engineer.
Step 1: Install GPT Engineer
First, you’ll need to install GPT Engineer. You can do this by cloning the repository from GitHub and installing the necessary dependencies.
Use pip install -e . on the repo to install all the dependencies.
Step 2: Define Your Prompt
Next, you’ll need to define the prompt for your app.
This is the instruction that you’ll give to the AI to generate the code for your app.

For our Weather Reporter app, the prompt could be something like:
Create a Python application that uses the OpenWeatherMap API to fetch and display the current weather for a given location. The application should ask the user for a location and then display the temperature, humidity, and weather description for that location.
CHATGPT4
Step Three: Create your Project
To do this let’s use the command from the repo readme.
cp -r projects/example/ projects/my-new-project
This will copy the files and folders from the example folder in the repo into a new project folder, and then
Step Four: Update the prompt in Your Project
gpt-engineer\projects\my-new-project\main_prompt
file to the one above or one of your choosing.
Step Five: Add Your Key
Create an account on open ai and generate a key, and then in the terminal execute
export OPENAI_API_KEY=your-key-here
NOTE: I highly recommend setting up a RATE LIMIT for your api key, so you don’t accidentally spend more than you want.
The prompt for this demo is quite simple and only cost me 14 cents to run but if your app prompt is more complex, who knows how much it could cost!

Step Six: Run GPT Engineer
gpt-engineer projects/my-new-project
If you set your key properly and have python installed and installed the repo dependencies properly, you’ll see something like the following.
Step Seven: Answer your Developer’s Questions
Now run this command
gpt-engineer projects/my-new-project
The GPT Engineer Terminal Experience
You’ll see my answers to the terminal based questions in italics and underlined.
Summary of areas that need clarification:
- Preferred method for user input (command line, GUI, etc.)
- Display format for the weather information
- Handling of API key for OpenWeatherMap
- Error handling and invalid user input
Clarifying question:
What method should be used for the user to input the location (e.g., command line, graphical user interface, etc.)?
(answer in text, or “c” to move on)
command line
3 remaining questions.
How should the weather information be displayed to the user?
(answer in text, or “c” to move on)
display the weather information in text format
2 remaining questions.
How should the OpenWeatherMap API key be handled and stored in the application?
(answer in text, or “c” to move on)
add an entry in an .env file and I’ll add myself after the =
1 remaining question.
How should the application handle errors and invalid user input?
(answer in text, or “c” to move on)
yes
Nothing more to clarify.
GPT Engineer Output
Core classes, functions, and methods:
main.py
: Entry point of the application, handles user input and output.weather.py
: Contains theWeather
class that fetches and stores weather data.openweathermap.py
: Contains theOpenWeatherMap
class that interacts with the OpenWeatherMap API.
Now, I will provide the content of each file.

main.py
import os
from dotenv import load_dotenv
from weather import Weather
def main():
load_dotenv()
api_key = os.getenv("OPENWEATHERMAP_API_KEY")
if not api_key:
print("Error: API key not found. Please set OPENWEATHERMAP_API_KEY in the .env file.")
return
location = input("Enter the location: ")
weather = Weather(api_key)
weather_data = weather.get_weather(location)
if weather_data:
print(f"Temperature: {weather_data['temperature']}°C")
print(f"Humidity: {weather_data['humidity']}%")
print(f"Weather description: {weather_data['description']}")
else:
print("Error: Unable to fetch weather data for the given location.")
if __name__ == "__main__":
main()

weather.py
from dataclasses import dataclass
from openweathermap import OpenWeatherMap
@dataclass
class WeatherData:
temperature: float
humidity: int
description: str
class Weather:
def __init__(self, api_key: str):
self.api = OpenWeatherMap(api_key)
def get_weather(self, location: str) -> WeatherData:
data = self.api.fetch_weather_data(location)
if data:
return WeatherData(
temperature=data["main"]["temp"],
humidity=data["main"]["humidity"],
description=data["weather"][0]["description"]
)
else:
return None

openweathermap.py
import requests
class OpenWeatherMap:
API_URL = "https://api.openweathermap.org/data/2.5/weather"
def __init__(self, api_key: str):
self.api_key = api_key
def fetch_weather_data(self, location: str) -> dict:
params = {
"q": location,
"appid": self.api_key,
"units": "metric"
}
response = requests.get(self.API_URL, params=params)
if response.status_code == 200:
return response.json()
else:
return None
.env
OPENWEATHERMAP_API_KEY=
requirements.txt
requests
python-dotenv
Please make sure to add your OpenWeatherMap API key after the = in the .env file.
pip install --user -r requirements.txt
python main.py
Do you want to execute this code?
pip install --user -r requirements.txt
python main.py
If yes, press enter. Otherwise, type "no"
no
Ok, not executing the code.
Important! Read the Code
You’re about to run the code that GPT Engineer created, be sure to actually read it, before running it.
Notice that I gave it a bad answer for how to handle errors, I just said yes, so it’ll be interesting to see how it interpreted the error handling response.
If you used the same prompt I did, then you’ll need to create an account for open weather.
Add your key after the OPENWEATHERMAP_API_KEY= in the .env file.
Now you’ll be able to run this code base with this command
sh run.sh
WARNING!
Don’t get frustrated when you inevitably get a 401 error, since it takes OpenWeatherMap 2 hours to actually set up your key.
Additional Warning
There are a few general security considerations you should be aware of before running any code on your computer:
API Keys
The application interacts with the OpenAI API, which requires an API key. This key should be kept secret.
NOTE: You’ll see that the .env file was added but there was no .gitignore file added in your repo by GPT engineer. This is a best practice and it looks like you’ll need to do it manually since you don’t want to accidentally commit that to github or wherever you’re going to publish your new project.

If your API key is exposed, it could be used by others, potentially leading to unauthorized access or usage charges. Make sure to store your API key securely and not include it in your codebase.
Code Execution
The application generates and executes code. This could potentially be a security risk if the generated code contains malicious instructions. Always review the generated code before executing it.
Data Privacy
The application may generate and store data based on your prompts. Make sure to review the data handling and storage practices of the application to ensure they meet your privacy requirements.
Dependencies
The application likely depends on external libraries. These libraries could have vulnerabilities that could be exploited. Always keep your dependencies up-to-date and review their security practices.
Open Source Code
The application is open source, which means its code is publicly available.

While this transparency can lead to better code quality and security, it also means that potential attackers can review the code for vulnerabilities. Always be cautious when using open source code and consider conducting a security review.
The Limit is your Imagination

I hope this opens up a whole new interesting world of creating and learning for you.