4 releases (breaking)

0.4.0 Nov 1, 2023
0.3.0 Mar 11, 2023
0.2.0 Mar 7, 2023
0.1.0 Mar 7, 2023

#6 in #gpt-3

44 downloads per month

MIT and AGPL-3.0-or-later

23KB
472 lines

heygpt

A simple command-line interface for ChatGPT API.

  • 🌟 Streaming output!
  • πŸ’‘ One-shot mode to get a quick answer
  • πŸ€– Interactive mode to have a conversation
screenshot

Demo (YouTube)

Quickstart

Install latest release version to $HOME/.cargo/bin/ via cargo:

cargo install heygpt

You'll need a OpenAI API key (you can get one here), and you'll need to export your API Key as an environment variable:

You can also set a OpenAI API base environment variable, just like openai-python

export OPENAI_API_KEY=<your api key>
# export OPENAI_API_BASE="https://api.openai.com/v1"

Then you can start an interactive conversation with ChatGPT:

heygpt

OR use the one-shot mode by providing a prompt:

heygpt how to record screen on mac

You can also compose prompt with bash tricks like

heygpt read the code and tell me what it is doing: $(cat src/main.rs)
heygpt read the code diff and write a commit message: $(git diff)
heygpt "please translate this poem to English:
> εΊŠε‰ζ˜Žζœˆε…‰οΌŒ
> η–‘ζ˜―εœ°δΈŠιœœγ€‚
> δΈΎε€΄ζœ›ζ˜ŽζœˆοΌŒ
> δ½Žε€΄ζ€ζ•…δΉ‘γ€‚"

You may even compose heygpt with other CLI tools via pipes:

$ echo "It's late. I should go to bed" | heygpt | cowsay
 ______________________________________
/ Goodnight! Sleep well and have sweet \
\ dreams.                              /
 --------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Advanced

Commands in interactive mode

Enter \? to see available commands:

user => \?
Available commands:
  \?, \help: Show this help
  \b, \back: Retract and back to the last user message
  \h, \history: View current conversation history

Configuration file

heygpt will load configurations from $HOME/.heygpt.toml. You may also set API keys and base URL here. Example:

model = "gpt-4"
api_base_url = "https://some.openai.mirror/v1"
api_key = "your api key"

Dependencies

~15–29MB
~432K SLoC