How to Install ChatGPT locally on your machine

Posted in ChatGPT on January 13, 2023 by Jessica Rose ‐ 4 min read

How to Install ChatGPT locally on your machine

10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

Now you can install ChatGPT locally on your local machine. To implement this, you will need to first install OpenAI API client.

Before proceeding, you must obtain an API key from OpenAI.

Follow the Below Steps to get the API Keys:

  1. Login to your OpenAI account (with Google or your Microsoft email ID or your personal email ID)

  2. Navigate to your Profile shown in the top right corner, and select the dropdown button.

ChatGPT api keys

  1. Select “View API Keys”

  2. Then under the “USER” section select the API KEYS

Chatgpt menu

  1. Simply click on Generate the API keys, to your new API keys please make sure, not to share it with anyone.

Chatgpt Generate Keys

Your secret API keys are listed below.Your secret API keys will not be displayed again after you generate them.

Do not share your API key with others, or expose it in the browser or other client-side code.

In order to protect the security of your account, OpenAI may also automatically rotate any API key that we’ve found has leaked publicly.

After obtaining the key, you can utilize the OpenAI API client by using the sample Node.js script and run the Chat GPT locally.

const openai = require('openai');

// Set your OpenAI API key
openai.apiKey = "YOUR_API_KEY";

// Set the prompt for Chat GPT
const prompt = "What's your favorite color?";

// Set the model to use (in this case, Chat GPT)
const model = "chatbot";

// Generate a response from Chat GPT
openai.completions.create({
  engine: model,
  prompt: prompt,
  max_tokens: 2048,
  n: 1,
  stop: '.',
  temperature: 0.5,
}, (error, response) => {
  console.log(response.choices[0].text);
});

To utilize the capabilities of OpenAI, I utilized the openai.completions.create() method to generate a response from Chat GPT, based on a given prompt.

By adjusting the max_tokens and temperature parameters, one can control the length and level of creativity in the generated response.

To gain a better understanding of how OpenAI functions, I created a copy of the Pet name generator app repository and attempted to create a Dockerized version of the solution. Initially, I tested the app on my local machine without utilizing Docker, to ensure that it was functioning correctly.


1. Clone the repository

git clone https://github.com/ajeetraina/openai-quickstart-node


2. Navigate into the project directory

cd openai-quickstart-node

3. Install the requirements

npm install

4. Copy of the example environment variables file

cp .env.example .env

Make sure to add the API key to the newly created .env file


5. Run the app

npm run build

You should now be able to access the app at http://localhost:3000!


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

Running a Random Pet Name Generator app using Docker Desktop

To utilize the Pet Name Generator app within a Docker container, it is necessary to first install Docker on your local system. A great option for personal usage is Docker Desktop, which is available at no cost.


Steps to install Docker:

docker image

  1. Go to the Docker website (https://www.docker.com/) and click on the “Get Docker” button.

  2. Select the appropriate version for your operating system. For example, if you are using Windows, select the “Docker Desktop for Windows” option.

  3. Click on the “Download” button and wait for the installation file to download.

  4. Once the download is complete, double-click on the downloaded file and follow the prompts to install Docker on your machine.

  5. After the installation is complete, open the Docker application and log in with your Docker account.

  6. Once you are logged in, you should see a message that Docker is running.

Please Note: Depending on your machine and the version of Docker you are installing, the steps may vary slightly. Be sure to refer to the official Docker documentation for detailed instructions for your specific operating system.


Creating a new directory

Navigate to the new folder/directory and create a new directory with mkdir. As shown below:

mkdir chatbot

Creating a docker file

Create a new Docker file, and specifically name it as Dockerfile as it makes easier for us to run it. Copy and paste the below command, in the docker file:

FROM node:14

## Install the OpenAI API client
RUN npm install openai

## Copy the app code to the container
COPY . /app

# Set the working directory to the app code
WORKDIR /app

# Run the app
CMD node app.js

The Dockerfile defines the foundation image (node:14) for the Docker container and incorporates the OpenAI API client.

Additionally, it transfers the application code to the container and establishes the working directory as the location of the app code.

To generate an app.js file, within your project folder, create a file named app.js and insert the following content into it:

const openai = require('openai');

// Set your OpenAI API key
openai.apiKey = "YOUR_API_KEY";

Building the Chat GPT Docker Image

Run the following command in your terminal.

docker build -t ajeetraina/chatbot-docker .

Running the Chat GPT container

docker run -d -p 8080:8080 ajeetraina/chatbot-docker

This tutorial should roughly take 15-20 mins with docker installation, and 5 mins if you have docker already installed.

Thank you for your Time. Have a Great Day!


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co