Skip to content

z8/gptcli

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Take chatGPT into command line.

stream

Setup

  1. clone this repo
  2. pip3 install -U -r requirements.txt
  3. get your OPENAI_API_KEY and put it in config.json

Run

$ ./gptcli.py -h
usage: gptcli.py [-h] [-c CONFIG]

options:
  -h, --help  show this help message and exit
  -c CONFIG   path to config.json (default: config.json)

Sample config.json:

{
    "key": "",                  // your api-key, will read from OPENAI_API_KEY envronment variable if empty
    "api_base": "",             // your api_base, will read from OPENAI_API_BASE envronment variable if empty
    "model": "gpt-3.5-turbo",   // GPT Model
    "stream": true,             // Stream mode
    "response": true,           // Attach response in prompt, consume more tokens to get better results
    "proxy": "",                // Use http/https/socks4a/socks5 proxy for requests to api.openai.com
    "prompt": [                 // Customize your prompt
        { "role": "system", "content": "Show your response in Markdown format with syntax highlight if it contains code, or just plaintext" },
        { "role": "assistant", "content": "OK" }
    ]
}

Supported model:

  • gpt-3.5-turbo
  • gpt-4
  • gpt-4-32k

Console help (with tab-complete):

$ ./gptcli.py
Input: -h
usage: Input [-help] [-reset] [-save FILE] [-load FILE] [-exit] [-multiline]

options:
  -help       show this help message
  -reset      reset session, i.e. clear chat history
  -save FILE  save current conversation to file
  -load FILE  load conversation from file
  -exit       exit console
  -multiline  input multiple lines, end with ctrl-d(Linux/macOS) or ctrl-z(Windows). cancel with ctrl-c

Run in Docker:

# build
$ docker build -t gptcli:latest .

# run
$ docker run -it --rm -v $PWD/.key:/gptcli/.key gptcli:latest -h

# for host proxy access:
$ docker run --rm -it -v $PWD/config.json:/gptcli/config.json --network host gptcli:latest -c /gptcli/config.json

Feature

  • Session based
  • Markdown support
  • Syntax highlight
  • Proxy support
  • Multiline input
  • Stream output
  • Single Python script
  • Save and load session from file

LINK

About

ChatGPT in command line with open api (gpt-3.5/gpt-4)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.1%
  • Dockerfile 1.9%