10x Your Productivity: Unleash the Power of ChatGPT on Your Terminal in 3 Simple Steps

Emin Gench
3 min readApr 10, 2023

--

10x Your Productivity: Unleash the Power of ChatGPT on Your Terminal in 3 Simple Steps

đź’Ą Do you want to 10x your productivity with the help of AI? đź’Ą Get ready to be amazed, as we reveal how to set up ChatGPT on your terminal to answer any question, provide expert advice, and even generate code! Say goodbye to endless searches and hello to the ultimate AI-powered knowledge base at your fingertips!

What is ChatGPT? ChatGPT is a powerful AI language model developed by OpenAI that can understand and respond to natural language queries. It’s like having a personal AI assistant who’s an expert in every field, ready to help you with anything you need!

Why Use ChatGPT on Your Terminal? By integrating ChatGPT into your terminal, you can:

  1. Access expert knowledge instantly
  2. Improve your workflow efficiency
  3. Reduce time spent searching for answers

Step-by-Step Guide to Setting Up ChatGPT on Your Terminal: Step 1: Install the OpenAI Python package In your terminal, run:

pip3 install openai

Step 2: Save the ChatGPT script Copy and paste the code below into a new file named “heygpt.py”. Create and account in Openai and put your OPENAI_API_KEY to your environment :

#!/usr/bin/env python3

import os
import openai
from argparse import ArgumentParser

openai.api_key = os.getenv("OPENAI_API_KEY")


def get_response(message: str) -> str:
# The conversation history up to this point, as a list of dictionaries
message_log = [
{"role": "system", "content": "You are an expert in every field. You are trying your best to help."}
]
message_log.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # The name of the OpenAI chatbot model to use
# The conversation history up to this point, as a list of dictionaries
messages=message_log,
# The maximum number of tokens (words or subwords) in the generated response
max_tokens=3000,
# The stopping sequence for the generated response, if any (not used here)
stop=None,
# The "creativity" of the generated response (higher temperature = more creative)
temperature=0.7,
)

# Find the first response from the chatbot that has text in it (some responses may not have text)
for choice in response.choices:
if "text" in choice:
return choice.text

# If no response with text is found, return the first response's content (which may be empty)
return response.choices[0].message.content


if __name__ == "__main__":
parser = ArgumentParser()
# short form: -m
parser.add_argument("-m", "--message",
help="message to send to the chatbot")
args = parser.parse_args()

print(get_response(args.message))

Step 3: Create an alias for the script In your shell configuration file (e.g., .bashrc or .zshrc), add the following alias:

alias heygpt="python3 /path/to/your/heygpt.py"

Don’t forget to replace “/path/to/your/” with the actual path to the “heygpt.py” file!

Now, you can easily use ChatGPT in your terminal by typing heygpt followed by your query, like this:

heygpt -m "How do I reverse a string in Python?"

Conclusion: Congratulations, you’ve successfully set up ChatGPT on your terminal! 🎉 Now you can enjoy lightning-fast access to expert knowledge, boosting your productivity like never before. Give it a try and watch your workflow efficiency skyrocket!

We’d love to hear about your experiences using ChatGPT on your terminal. Share your thoughts and insights in the comments below, and let’s continue to revolutionize productivity together! 🚀

--

--

Emin Gench

Hi, I'm Emin GENCH, an Aerospace Engineering graduate turned self-taught Software Engineer. Passionate about coding, problem-solving, and sharing my journey.