Conversate or talk with ChatGPT in your own terminal

axlfc

Axlfc

Posted on December 3, 2022

Conversate or talk with ChatGPT in your own terminal

Here's how I managed to use ChatGPT AI chat bot in my own terminal.

A screenshot of ChatGPT running on my Android Phone in Termux App

If you want to recreate the running of the script manually, follow the steps below:

chatGPT

  • Install Python3 and Git

GNU/Linux:
sudo apt-get install -y python3 git

Termux (Android):
pkg install -y root-repo
pkg update -y
pkg upgrade -y
apt install -y git build-essential python3

  • Install Python dependencies

GNU/Linux:
pip3 install openai python-dotenv transformers colorama

Windows:
pip install openai python-dotenv transformers colorama

Termux (Android):
MATHLIB="m" pip3 install numpy openai
pip3 install wheel setuptools python-dotenv colorama

  • Clone git repository
    git clone https://github.com/Axlfc/UE5-python

  • Navigate to Content/Python/chatBot repository directory

  • Log into openAI web page and get your API key.

  • Edit .env file from the repository folder and paste your API Key to set the variable OPENAI_API_KEY

  • Run conversate.py to begin to conversate with the AI locally on your terminal.

GNU/Linux & Termux (Android):
python3 conversate.py

Windows:
python conversate.py

If you want to run a simple command chat to run chatGPT in Windows Terminal, you can edit the C:\Users\Your_Username\Documents\WindowsPowershell\Microsoft.PowerShell_profile.ps1 file and add to it the following lines:

function chat_function {
python C:\Users\Your_Username\Desktop\UE5-python\Content\Python\chatBot\conversate.py
}
Set-Alias chat chat_function

If you also want that chat alias in GNU/Linux or Android, you can edit ~/.bash_aliases file and add:

chat() {
python3 "~/UE5-python/Content/Python/chatBot/conversate.py"
}

Now when you type chat in your Terminal it will start chatGPT.

talkGPT

If you want the AI to talk to you using a concrete voice, you should try running talk.py script which is used to make the AI process an audio file of their response, for the moment voice chat works only on Windows or GNU/Linux:

-Install portaudio
GNU/Linux:
sudo apt-get install -y build-essential portaudio19-dev

  • Install the required Python dependencies and it should work:

GNU/Linux:
pip3 install git+https://github.com/openai/whisper.git jiwer gitpython gdown pathlib setuptools pyaudio soundfile pathlib numpy librosa SpeechRecognition langdetect googletrans==4.0.0-rc1

Windows:
pip install git+https://github.com/openai/whisper.git jiwer gitpython gdown pathlib setuptools pyaudio soundfile pathlib numpy librosa SpeechRecognition langdetect googletrans==4.0.0-rc1

  • Run talk.py to begin to talk with the AI locally on your terminal, the voice will process and then played.

GNU/Linux:
python3 talk.py

Windows:
python talk.py

Voice processing in talk.py script isn't able to mantain a conversation (almost) real time with the ChatGPT AI due to long audio processing time, but it is definitely possible.

codeGPT

If you only want the AI to generate code for you, use the script code.py and pass some commented code to it and it will reply creating code for you!

code.py execution

Did this article helped you? Share it, comment or give a like if it did! 😄

💖 💪 🙅 🚩
axlfc
Axlfc

Posted on December 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related