ChatGPT Wrapper – Use ChatGPT directly from the command Line

Use ChatGPT From Your Terminal Using A Python Wrapper

ChatGPT is an AI chatbot and was launched by OpenAI in November 2022. It can perform various tasks such as writing and debugging code, writing stories, and mimicking a human conversation and so on. It is free to use as of now, however, there are plans to monetize the AI.

You can access it from their website. However, you can also use the unofficial ChatGPT Wrapper, which is an open-source command line tool which can be used to interact with the famous AI ChatGPT directly from the Terminal or in your Python scripts.

Also Read: How to search and watch YouTube videos directly from the terminal

Using this python wrapper, you can navigate to past points in the conversation and log everything that is being written. It also has the ability to restore any context from the logs and also read prompts from files.

Installing ChatGPT Wrapper

In this tutorial, we will see how we can install this tool and also log into our OpenAI account and discuss the usage of ChatGPT wrapper.

Install the dependencies

First, we will have to install the python dependencies on your system. Just open a Terminal window and type the following commands, depending upon your Linux distribution:

On Debian and Ubuntu based distributions:

sudo apt install python3-setuptools python3-pip git

On openSUSE Linux, you can type the following commands:

sudo zypper install python3-setuptools python3-pip git

On Fedora Workstation, you can type:

sudo dnf install python3-setuptools python3-pip git
Installing The Dependencies On Fedora Workstation
Installing The Dependencies On Fedora Workstation

On Arch Linux based distributions:

sudo pacman -S python-setuptools python-pip git

Because it uses the Playwright package to interact with your browser, you should also install that package. Type the following commands irrespective of your Linux distribution:

pip install playwright
Installing Playwright Using Pip
Installing Playwright Using Pip

Install the package

Once the dependencies has been installed, you can just install the package by typing the following commands:

pip install git+https://github.com/mmabrouk/chatgpt-wrapper
Installing The ChatGPT Wrapper On Linux
Installing The ChatGPT Wrapper On Linux

Now, using the playwright package, install a web browser, preferably Firefox. This will help us to authenticate and log into our OpenAI account. Type:

playwright install firefox
Install Firefox Browser For Authentication Using Playwright
Install Firefox Browser For Authentication Using Playwright

Now, type the following command using ChatGPT wrapper to authenticate yourself:

chatgpt install

This command will open a new browser window, and you will have to either log into your existing OpenAI account or simply create a new ID using your e-mail.

Log Into Your OpenAI Account
Log Into Your OpenAI Account

Once logged in, you should go through the process of clicking ‘next’ buttons until you reach the chat box page. Simply close the browser window now and press ‘q’ in the Terminal to stop the running process.

Now, again, type the following command to summon ChatGPT wrapper:

chatgpt
Asking Questions To ChatGPT From The Terminal
Asking Questions To ChatGPT From The Terminal

You can now use the ChatGPT Wrapper to ask questions to ChatGPT without ever opening a web browser. In order to see the list of available commands, you can type ‘?’ in the ChatGPT wrapper mode. For example, typing !new in the prompt will start a new conversation with ChatGPT for you.

Summary

You should know that this wrapper can be slow depending upon the questions you have asked because it first asks your question to ChatGPT in the browser. And when the AI finishes answering your question, ChatGPT Wrapper will then collect its output and then report it back to the console. And you will have no indication in the Terminal while it does that. Which might lead you to think that it is not working.

But overall, it’s a fun tool to play with since ChatGPT hasn’t released an official API yet. Maybe once that happens, you will not longer need this hack. But until then, this ChatGPT wrapper is a great alternative to use.

Recommended read

Search for Text inside a PDF document using PDFgrep