How To Set up And Use ChatGPT In Linux Terminal

How To Set up And Use ChatGPT In Linux Terminal

How To Set up And Use ChatGPT In Linux Terminal

ChatGPT is creating a storm on the Internet. Almost everyone is talking about it and also using it. Everyone wants to eat the pie of its popularity by using it or integrating it. Meanwhile, in this article, we will discuss the method of using ChatGPT in Linux and that one in Linux terminal.

How To Set up And Use ChatGPT In Linux Terminal

We will take the help of ShellGPT in Linux to use ChatGPT. ShellGPT is developed by Farkhod Sadykov, Eric, and Loïc Coyle. Before installing ShellGPT in Linux, you need to have python installed. Python comes preinstalled on most latest Linux distros. So run the following command to the python version installed on your Linux.

python3 --version

If you see any errors, then the python is not installed or the deprecated python2.7 is installed on your system. If an older version of Python is installed, run the below command to update Python to the latest version.

sudo apt --only-upgrade install python3

If there is no python installed in your system, then run the following command to install Python:

For Ubuntu:

sudo apt update && sudo apt upgrade -y
sudo apt install python3

Install Pip Package Manager:

READ More Relevant Stuff:  Best Home Theater Power Managers And Conditioners

It generally comes preinstalled with Python in most Linux distributions, but if it is not installed, you can install it with this command:

sudo apt-get -y install python3-pip

Now, let’s begin the process of installing ShellGPT on Linux.

Run the following command to create a directory.

mkdir <new_directory_name>

Switch over to the new directory you just created with the following command:

cd <new_directory_name>

Now, run the following command to create a new virtual environment. First, install the venv model.

sudo apt install python3-venv
 python3 -m venv  

The virtual environment you just created will be deactivated by default. Run the following command to activate the environment:

source /bin/activate

Get Your OpenAI API Key

We need to have OpenAI API key to use ChatGPT’s services in Linux. For this:

1. Navigate to OpenAI’s website and create a new OpenAI account. If you already have an account, simply log in and move to the next step.

2. Next, click on your profile image at the top right corner and select “View API keys” from the drop-down menu.  Here, you will see all the previously generated API Keys if any.

3. To generate a new API key, click the “Create new secret key” button. Do not share this API key with anyone or share it publicly. Now, create an environment variable for this API key with the command below.

export OPENAI_API_KEY=<your_OpenAI_API_key_here_API key you generated to use ChatGPT>

Verify the environment variable by listing it with the env command:

env

To store the API key permanently, open the .bashrc file in the text editor and add the variable at the end of the file.

export OPENAI_API_KEY=<your_OpenAI_API_key_here_API key you generated to use ChatGPT>

Save the file and exit the text editor after you have added the OpenAI API key.

READ More Relevant Stuff:  10 Best Minecraft Seeds In 2023

Install ShellGPT to Use ChatGPT on Linux

Now run the following  command to install ShellGPT on your PC:

pip3 install shell-gpt --user

How to Use ChatGPT in Linux with Examples

Run the following command to get the result.

For example, if you need to know the goal record of the messi, use this command:

sgpt " goal record of the messi"

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *