/Hello-ChatGPT

ChatGPT with FastAPI

Primary LanguagePythonApache License 2.0Apache-2.0

Python 3.x

logo

ChatGPT API with FastAPI

This repository contains a simple implementation of a ChatGPT API using FastAPI and OpenAI's GPT model. The API allows users to input a prompt and generate a response from the model.

Up to 10 messages are stored in Redis. The cache allows the conversation to continue with ChatGPT.

Prerequisite

  • Docker
  • Redis

Before running the application, make sure that Docker and Redis are installed and running on your system.

important: Set and use all the environment variables in app/config/constants.py.

Local Execution Guide

  1. First, to run this application in your local environment, please execute the following command to install the required libraries.
pip install -r requirements.txt
  1. Once the necessary libraries have been installed, execute the following command to run the application.
uvicorn app.main:app --reload

This command will run the application based on the app object in the main module of the app package. You can use the --reload option to automatically reload the application when file changes are detected.

Installation

  1. Clone the repository:
https://github.com/jybaek/Hello-ChatGPT.git
cd Hello-ChatGPT
  1. Build the Docker image:
docker build -t chatgpt-api .
  1. Run the Docker container:
docker run --rm -it -p8000:8000 chatgpt-api
  1. Open your web browser and go to http://localhost:8000/docs to access the Swagger UI and test the API.

API Documentation

The API documentation can be found at http://localhost:8000/docs once the Docker container is running.

Usage

image You can save and continue conversations based on user_id. Just put in a value that identifies the user. For example, you can use the user's unique number, session information, etc. stored in the database.

  • user_id: This is the parameter that identifies the user. Conversations will be stored and retrieved based on this parameter. In other words, the chat history with User A will be separate from the chat history with User B.
  • number_of_messages_to_keep: This parameter specifies how many recent messages to keep in the chat history. It's generally better to keep more messages, but keep in mind that this can impact the cost of ChatGPT.
  • `For the remaining parameters, please refer to the following link for more details: https://beta.openai.com/docs/api-reference/completions/create. This link provides the API reference for creating completions with ChatGPT.

License

This project is licensed under the terms of the MIT license. See LICENSE for more information.