LinuxCommandLibrary

chatgpt

Interact with the ChatGPT language model

TLDR

Start in chat mode

$ chatgpt
copy

Give a prompt to answer to
$ chatgpt [[-p|--prompt]] "[What is the regex to match an email address?]"
copy

Start in chat mode using a specific model (default is gpt-3.5-turbo)
$ chatgpt [[-m|--model]] [gpt-4]
copy

Start in chat mode with an initial prompt
$ chatgpt [[-i|--init-prompt]] "[You are Rick, from Rick and Morty. Respond to questions using his mannerism and include insulting jokes.]"
copy

Pipe the result of a command to chatgpt as a prompt
$ echo "[How to view running processes on Ubuntu?]" | chatgpt
copy

Generate an image using DALL-E
$ chatgpt [[-p|--prompt]] "[image: A white cat]"
copy

SYNOPSIS

chatgpt [options...] [prompt]

PARAMETERS

-h, --help
    Show help message and exit

-v, --version
    Display program version

-m, --model <MODEL>
    Select model, e.g., gpt-3.5-turbo or gpt-4 (default: gpt-3.5-turbo)

-r, --role <ROLE>
    Reply in specified role (e.g., coder, teacher)

-s, --stream
    Stream response in real-time

-p, --proxy <PROXY>
    Use specified proxy URL

-c, --clear
    Clear terminal screen before output

-M, --markdown
    Format output as Markdown

-o, --output <FILE>
    Save conversation to file (default: Untitled.md)

-t, --test
    Test API connection

-k, --key <KEY>
    Provide OpenAI API key directly

DESCRIPTION

The chatgpt command provides an unofficial command-line interface to OpenAI's ChatGPT models, enabling seamless interaction from the Linux terminal. Ideal for developers, sysadmins, and power users, it supports querying AI for code assistance, explanations, or creative tasks without leaving the shell.

Installation typically involves Python's pip: pip install chatgpt-cli (from acheong08/ChatGPT repo). An OpenAI API key is required, obtainable from platform.openai.com. Basic invocation sends a prompt and streams or prints the response.

Key features include model selection (gpt-3.5-turbo or gpt-4), response streaming for real-time output, markdown formatting, conversation saving to files, proxy support for restricted networks, and role-playing modes. It maintains session context optionally via --continue, though primary use is stateless prompts.

Responses are colored and formatted for readability. Advanced scripting integrates it into pipelines, e.g., with jq for JSON parsing. While convenient, usage incurs API costs based on tokens processed.

CAVEATS

Requires paid OpenAI API key; unofficial tool may break on API changes; respects rate limits and token costs; potential privacy risks with prompts.

INSTALLATION

pip install 'chatgpt[clip]' or clone from GitHub and pip install -e .; set OPENAI_API_KEY env var.

EXAMPLES

chatgpt 'Explain Linux pipes'
chatgpt -m gpt-4 -s -M 'Write a bash script'
chatgpt -t to verify setup.

HISTORY

Developed by acheong08 in late 2022; started as reverse-engineered web client, evolved to official OpenAI API support in v0.9+; widely forked with 10k+ GitHub stars.

Copied to clipboard