Building a Simple Chatbot using GPT model - part 1
Tags: ai, python, llm
Published: 2024-05-24 06:40:16

I have been wanting to understand the vulnerabilities related to Large Language Model (LLM) applications and generative AI, so I thought a good way to understand these in practice would be by first developing my own chatbot.

So here's a two-part series where I go through what LLMs are, how to set up a development environment, and how to actually develop a chatbot.

This first post helps you set up the environment, as well as explains what LLMs are. In a [post next week](https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn), I will go through the development of the chatbot.

### What are LLMs?

LLM stands for Large Language Model. It is a system designed to understand and generate human-like text. LLMs are trained with vast amounts of data from various sources, such as books, articles, and websites. This allows the algorithm to predict what sequences of words are probable responses to a user-provided input.

One example of a system using an LLM, which probably everyone has heard about by now, is [ChatGPT](https://openai.com/chatgpt/). It is an AI system that uses natural language processing to create a conversation with the user and utilizes OpenAI's Generative Pre-trained Transformer (GPT), a neural network machine learning model.

### Setup the Environment

Now that you have the background info for this series, let's set up our environment.

I'm using WSL 2 with Ubuntu 20.04 LTS, so if you are not using the same setup, the commands I use might be a little different on your distribution.

#### 1. Update and Upgrade Ubuntu

Open your Ubuntu terminal and run the following commands to update and upgrade your package lists:

```
sudo apt update
sudo apt upgrade
```
This will ensure you have the latest software updates.

#### 2. Install Python

This guide will use Python and pip to run the required Python scripts and manage packages. Most Ubuntu installations come with Python pre-installed. Verify the installation by running the following commands:

```
python3 --version
pip3 --version
```

If Python or pip is not installed, install them using this command:

```
sudo apt install python3 python3-pip
```

#### 3. Install Virtual Environment Tools

Creating a [virtual environment](https://docs.python.org/3/library/venv.html) is a best practice to manage dependencies for your projects. This will create an isolated environment that prevents conflicts between different projects that may require different versions of the same package.

Install venv by running:

```
sudo apt install python3-venv
```

#### 4. Create a Virtual Environment

Navigate to the directory where you want to create your project and set up a virtual environment:

```
mkdir name-of-directory
cd name-of-directory
python3 -m venv venv-name
```

- mkdir name-of-directory: Creates a new directory called _name-of-directory_ for your project. Change the name to what you want it to be.
- cd name-of-directory: Changes the current directory to the directory you just created.
- python3 -m venv venv-name: Creates a virtual environment named _venv-name_ in the directory. Change the name to what you want it to be.

#### 5. Activate the Virtual Environment

Activate the virtual environment with the following command, changing _venv-name_ to the one you chose when creating the virtual environment in the step above:

```
source venv-name/bin/activate
```

You should see the virtual environment name (e.g., _venv-name_) in your terminal prompt, indicating that it's activated.

```
(venv-name) example@ubuntu:/name-of-directory$
```

#### 6. Upgrade pip

Ensure that pip is up to date:

```
pip3 install --upgrade pip
```

### That's it!

In this blog post, we set up the environment so it is ready when we start building the chatbot on the [next post](https://dev.to/whatminjacodes/building-a-simple-chatbot-using-gpt-model-part-2-45cn) that I'm publishing next week!

You can also follow my Instagram [@whatminjahacks](https://www.instagram.com/whatminjahacks/) if you are interested to see more about my days as a Cyber Security consultant and learn more about cyber security with me!