Skip to main content

Command-line interface tool for interacting with ChatGPT using terminal

Project description

ChatGPT - Command-Line Interface

CLI tool for interacting with ChatGPT using terminal

Requirements

  • Python >= 3.8.0
  • OpenAI account and valid API key

Installation

Tool can be installed using python3 pip command:

pip install chatgpt-cli-tool

Or you can install it directly form this project after building it:

python build.py

pip install dist/chatgpt-cli-tool-{version}.tar.gz

Configuration

In order to use ChatGPT cli you will first need to register and create an API key on the official OpenAI website.

Then you can configure the tool with your API key using any of the following options:

  1. Create an ~/.chatgpt-cli/.env file with variable OPENAI_API_KEY
  2. Create an .env file in the working directory with variable OPENAI_API_KEY
  3. Set it through environment variable OPENAI_API_KEY
  4. Pass it as the first argument when executing this tool (e.g. chatgpt-cli my_api_key)

All configurable environment variables for ChatGPT can be found in .env.example file:

Variable name Description Default value
OPENAI_API_KEY OpenAI API key used to send request -
GPT_MODEL GPT model used for chat completion gpt-3.5-turbo
GPT_SYSTEM_DESC The description for the system on how to best tailor answers (disable with "None") You are a very direct and straight-to-the-point assistant.
GPT_IMAGE_SIZE The generated image size (256x256, 512x512 or 1024x1024) 512x512
HISTORY_SIZE Number of last messages to keep in history as a context for the next question 3
CHAT_TEXT_WIDTH Maximum number of characters to display per line in interactive chat mode (0 - as much as possible) 0
CHAT_COLORED Enable this to use colors in interactive chat mode true
CHAT_COLOR_YOU The color used for your inputs green
CHAT_COLOR_AI The colore of AI responses white

Running the CLI

If you installed the tool using pip, then simply start the cli using any of the following commands:

chatgpt-cli [api_key]

This command starts interactive ChatGPT where you can chat with AI in form of a dialog.

# with api key
chatgpt-cli my_api_key

# without api key
chatgpt-cli

gpt-ai [api_key] [query]

This comand sends single chat completion prompt for given query or content, and prints the result on stdout.

# with api key and query argument
gpt-ai my_api_key "What is ChatGPT?"

# with query argument
gpt-ai "What is ChatGPT?"

# with api key and piped input
cat file.txt | gpt-ai my_api_key

# with query from stdin
cat question.txt | gpt-ai

# with both query as argument and piped input
cat long-story.txt | gpt-ai "sumarize this text in 5 bullet points"

# with both query as argument and input directly from file
gpt-ai "explain this code" < main.py

gpt-img [api_key] [prompt] [img_out]

This comand generates image for given prompt or content, and stores the image in provided output path or if not specified, prints the binary result on stdout. Some terminals like PowerShell might malform the binary content when outputing to file.

# with api key, prompt and output image path
gpt-img my_api_key "Robot walking a dog" ./my-images/image.png

# without api key
gpt-img "Robot walking a dog" ./my-images/image.png

# without output image path, the binary image data will be outputed to stdout
gpt-img "Robot walking a dog" > image.png

# with both piped input and argument prompts
cat description.txt | gpt-img "with cartoon graphics" ./image.png

# with only piped input and output image file
cat description.txt | gpt-img ./image.png

# with only piped input and output image directed to file
cat description.txt | gpt-img > ./image.png

# with only input directly from file, binary image data will be outputed to stdout
gpt-img < idea.txt

API key argument is optional for all commands, but if provided it will override API key defined using environment variables.

Recommendations

ChatGPT-Slackbot

If you are a regular Slack user, check out my other project which provides seamless ChatGPT and Slack integration: https://github.com/lmatosevic/chatgpt-slackbot

License

ChatGPT-Cli is MIT licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chatgpt-cli-tool-1.4.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

chatgpt_cli_tool-1.4.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file chatgpt-cli-tool-1.4.0.tar.gz.

File metadata

  • Download URL: chatgpt-cli-tool-1.4.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.2

File hashes

Hashes for chatgpt-cli-tool-1.4.0.tar.gz
Algorithm Hash digest
SHA256 ba6f00f4ab1c02031cb4da4b9121b6900d1daaad79146d4c4ab1eb932590616d
MD5 6b200ec13e17ae530421712e7e205d1d
BLAKE2b-256 16801a7f8ecc8931544720f53c67e3114476a7e118e7435cb599eab06758303c

See more details on using hashes here.

File details

Details for the file chatgpt_cli_tool-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: chatgpt_cli_tool-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.2

File hashes

Hashes for chatgpt_cli_tool-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9090f9cfe9051881662c884b375a4606c3c918f9a3acc265f8d99c0ace4f3b54
MD5 9502eb62a55deb6d42abc467025217da
BLAKE2b-256 599df5d8acd9e8ae3179cd94f4e1f3a8b6fc0e403f67ebec6c82d013651d299f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page