Coder Social home page Coder Social logo

hello-chatgpt's Introduction

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.

hello-chatgpt's People

Contributors

jybaek 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.