Skip to content

Latest commit

 

History

History
96 lines (61 loc) · 3.56 KB

README.md

File metadata and controls

96 lines (61 loc) · 3.56 KB

ChatGPT Clone For Terminal/CLI

This is a ChatGPT API integration straight to the terminal/CLI. Here, we're building an interactive chatbot using OpenAI, implemented in Python, and supported by various packages such as Typer for command line interface creation. Follow along to set up and get this project up and running on your machine :)

Login

Prerequisites

  • Python 3.11 (recommended to use pyenv for managing Python versions)
  • OpenAI API key
  • Python packages: typer, python-dotenv, and others specified in the project

Setup

1. Python Environment Setup

We are using pyenv to manage our Python installations and pyenv-virtualenv for creating virtual environments. Instructions are provided for macOS. Refer to the official documentation for Windows or Linux installations.

Install pyenv:

brew install pyenv

Install pyenv-virtualenv:

brew install pyenv-virtualenv

2. Project Dependencies

Once you have the appropriate Python version installed and a virtual environment set up, install the project dependencies:

pip install -r requirements.txt

3. OpenAI API Key Configuration

You will need an OpenAI API key for this project. Store it securely using environment variables.

touch .env
echo "OPENAI_API_KEY=your-api-key" >> .env

Replace "your-api-key" with your actual OpenAI API key.

Note: Ensure you have sufficient OpenAI API credits, as each request to the API may incur a cost.

Project Initialization

Create a directory for the project, set up your virtual environment, and activate it:

mkdir chatgpt-clone
cd chatgpt-clone
pyenv virtualenv 3.11.0 chatgpt-clone-env
pyenv activate chatgpt-clone-env

Login

Coding and Running the Chatbot

Now, dive into the code. Start by creating a main.py file in your project directory, and import all necessary dependencies. This project uses typer for CLI interactions, python-dotenv for secure API key storage, and the openai package for core functionality.

  1. Setting up the application command:

    • Use Typer decorators to create interactive command-line applications.
  2. Handling user interactions:

    • Implement functions to handle user inputs and communicate with the OpenAI API.
  3. Processing API responses:

    • Parse the JSON responses from the OpenAI API to extract relevant information.
  4. Enhancing chatbot memory:

    • Implement context handling for more coherent conversation with the chatbot.
  5. Customizing chatbot parameters:

    • Allow customization of various parameters (e.g., max_tokens, temperature) directly from the command line.
  6. Optimizing user experience:

    • Enhance the initialization process to start a conversation immediately upon launching the program.

Run your chatbot:

python main.py --help  # To display help information and available commands
python main.py --max-tokens 150  # Example command to customize token limit

Licensing

The code in this project is licensed under MIT license.