Coder Social home page Coder Social logo

chatgpt-in-terminal's Introduction

Chat with GPT in terminal

English badge 简体中文 badge Platform badge standard-readme compliant

This project implements a ChatGPT chatbot in the terminal.

  • The Markdown content in the responses is rendered as beautiful rich text

  • Historical questions can be retrieved via the up/down arrow

  • Optional multi-line queries

  • Token counting

example

The latest gpt-3.5-turbo model is used, which is the model used by ChatGPT free version (rather than the previous generation text-davinci-003 model).

Install

  1. Clone the repo and navigate to the directory:

    git clone https://github.com/xiaoxx970/chatgpt-in-terminal.git
    cd ./chatgpt-in-terminal
  2. In the .env file at the root of the project, write the OPENAI_API_KEY variable, as follows:

    OPENAI_API_KEY=your-API-KEY
    

    OpenAI's key can be generated on the page that opens when you click View API keys in the top right corner of the main page, direct link: https://platform.openai.com/account/api-keys.

    image-20230303233352970

    If you don't configure the .env file, you can also directly input the API KEY at runtime, which will only take effect for that single run.

  3. Install dependencies via requirements.txt:

    pip3 install -r requirements.txt

Usage

Run the following command to start the bot:

python3 chat.py

The conversation record in its original format will be stored in chat.log.

Multi-line mode

If the question requires multi-line input, run the command with the -m parameter:

python3 chat.py -m

In multi-line mode, press Enter to move to the next line, and if you press Enter on a blank line, the question will be submitted.

Raw mode

If you would like answers that are not rendered with Markdown, run the command with the -raw parameter:

python3 chat.py -raw

Multi-line and raw modes can be used simultaneously.

Exit word

In the chat, you can end the session with an exit word, which can be:

['再见', 'bye', 'goodbye', '结束', 'end', '退出', 'exit']

The exit word will be sent as a question to ChatGPT, and the bot will exit after GPT provides an answer.

You can also use Ctrl-C or Ctrl-D to exit immediately.

After exiting, the bot will display the token count used in the chat.

Currently priced at: $0.002 / 1K tokens, the free version has a speed limit of: 20 times / min.

Project structure

├── README.md           # Documentation file
├── chat.py             # Project code
├── requirements.txt    # List of dependencies
├── chat.log            # Log file generated after chatting
└── .env                # Key storage file

License

This project is licensed under the MIT License.

chatgpt-in-terminal's People

Contributors

xiaoxx970 avatar

Stargazers

Ashfaaq Rifath avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.