Text to Code: Easy Step by Step Guide for GPT-Engineer

GPT-Engineer has transformed the app development process by allowing developers to describe their project and having code created automatically. GPT-Engineer eliminates the need to manually copy/paste code, create files, or configure project environments.

In this article how to install GPT Engineer and single prompt using generate a code and resolving any potential errors that may arise during the process.

Prerequisites

A computer with Python Installed. Python needs to be executable using python command.

Configure Python

If you don’t have Python configured to be executed with python command you can follow to below steps.

Check which Python you have. Execute the below command.

type python python2 python3

You will see some output similar to the one below.

-bash: type: python: not found -bash: type: python2: not found python3 is /usr/bin/python3

This indicates that you have Python executable as python3 and not as python.

Create a symlink of python3 to python inside the /usr/bin directory.

sudo ln -s /usr/bin/python3 /usr/bin/python

Now you can run Python using python command.

python -version Output Python 3.10.6

Now we have Python up and running.

Install Required packages for GPT-Engineer

Now we need some packages for smooth code execution for Python.

sudo apt install build-essential libssl-dev libffi-dev python3-dev

Install Python Virtual Environment.

sudo apt install python3-venv -y

Now we have all necessary packages to install and configure GPT Engineer.

See also  AI Photo to Sketch: Best Way to Turn Your Photos into Sketches

Install GPT-Engineer

To begin, you need to create your project directory.

mydir website

Navigate to your directory.

cd website

Clone the GPT Engineer repository from GitHub.

git clone https://github.com/AntonOsika/gpt-engineer.git .

Install GPT Engineer

make install

You will see an output similar to the one below.

Creating virtual environment… Upgrading pip… Installing dependencies… Installing pre-commit hooks… pre-commit installed at .git/hooks/pre-commit All done!

Activate virtual environment.

source venv/bin/activate

Configure the API Key

To interact with the OpenAI API, you must first create an API key. Get your OpenAI API key and execute the following command, depending on your operating system:

For macOS/Linux:

export OPENAI_API_KEY=[your api key]

For Windows:

set OPENAI_API_KEY=[your api key]

Create a Text to Code with GPT Engineer

GPT-Engineer provides an interface via the prompt file, which is available in the projects folder. There is a “example” folder by default, which contains a sample project.

If you wish to start a new project, use the following command to create a new empty folder:

Replace website with the name of your project’s folder.

cp -r projects/example/ projects/website

Then, inside your project folder, modify the prompt file to outline your project needs. This is where you provide GPT-Engineer instructions or prompts to generate the desired code.

After you’ve edited the prompt file, launch GPT Engineer with the following command:

gpt-engineer projects/website

Refer to GPT Engineer: The Next Generation of AI-Powered Development for your distribution including information about to setup environment and more

The created files will be stored in the workspace directory within your project folder. You can examine the created code files as well as other artifacts.

See also  Types of AI: Interactive, Generative What They Are and How They Work

While GPT-Engineer strives to automate code generation, you may still encounter problems or need to make manual changes to get the resulting code to work as desired.

Web Scraping

  • Create a Python snake game using the Model-View-Controller (MVC) architecture with GPT-Engineer. This example can be done in above mention article for further information. The game’s components into individual files and added keyboard control. However, for this demonstration, to change the prompt to focus on web scraping.
  • In example1 extract article titles from the website “https://cloudbooklet.com/” using GPT-Engineer.
Gpt-Engineer
Text to Code: Easy Step by Step Guide for GPT-Engineer 1
  • The titles are contained within the h1 tag, and the scraped data is exported to a CSV file.
  • To launch GPT-Engineer, type “gpt-engineer projects/website” (change “website” with the name of your preferred project). The created files can be located in the “projects/website/workspace” directory once completed.
  • These files contain Python scripts that handle the scraping process as well as a CSV file with the retrieved data.

Creating a Web App

To look on developing a web app. With minimal prompt input of “Create a website about cartoon,” GPT-Engineer generates relevant files to kickstart the development process.

Create a website about cartoon

Then execute the command to create a website.

gpt-engineer projects/website Specification: The program is a website about cartoon. It should have the following features: 1. Home page: A landing page that displays a welcome message and a list of cartoons. 2. page: A page that displays information about a specific cartoon, incl uding a picture, description, and characteristics. 3. Search page: A page that allows users to search for cartoon by name or cha racteristics. 4. Contact page: A page that allows users to send a message to the website owner 5. Admin page: A page that allows the website owner to add, edit, or cartoon. Core classes, functions, and methods: 1. cartoon: A class that represents a cartoon, with attributes such as name, picture, description, and characteristics.

See also  How to Take Fantastic LinkedIn Headshots in 2023 (6 Simple Steps)

After running the gpt engineer website command, continue by clicking on the yes/no option.

To install dependencies: python3 -m venv env source env/bin/activate pip install -r requirements. txt To run the codebase: python3 opp.py Do you want to execute this code? python3 -m venv env source env/bin/activate pip install -r requirements. txt python3 app.py If yes, press enter. Otherwise, type “no”

Here the cartoon website with all python files will be created by single prompt using GPT Engineer.

Gpt-Engineer
Text to Code: Easy Step by Step Guide for GPT-Engineer 2

However, a single prompt is used to get the web app up and running successfully.

Nonetheless, GPT-Engineer seems to be a beneficial tool for speeding up the app-development process also.

Also read: You might also find useful our guide on Gamma AI Presentations Slides PPT for your Meetings

Conclusion

Finally, GPT-Engineer provides a robust solution for easily producing code and building apps. It streamlines the development process by understanding project descriptions and creating the relevant files. Although some adjustments may be necessary, GPT Engineer demonstrates the ability of AI in automating code production and empowering developers. Investigate its skills to discover new possibilities in your coding path.

Please feel free to share your thoughts and feedback in the comment section below.