Skip to content

Latest commit

 

History

History
65 lines (40 loc) · 1.68 KB

README.md

File metadata and controls

65 lines (40 loc) · 1.68 KB

GPT-API

This project integrates the OpenAI API with a FastAPI server to create a conversational AI system. It utilizes environment variables for API keys and includes routes for starting conversations and chatting with the AI.

Installation

Before you start, make sure you have Python installed on your system.

  1. Clone the repository:
git clone git@github.com:thissayantan/gpt-api.git
  1. Navigate to the cloned directory:
cd gpt-api
  1. Install the required packages:
poetry install

Configuration

Create a .env file in the root of the project and set the OPENAI_API_KEY variable:

OPENAI_API_KEY='your-openai-api-key'

Running the Server

Start the FastAPI server with:

uvicorn main:app --reload

The --reload flag enables hot reloading during development.

Usage

Once the server is running, you can interact with the API as follows:

  • Send a GET request to the root (/) to verify that the server is running.
  • Start a conversation with a GET request to /start. This will return a thread_id.
  • Use the thread_id to chat with the AI by sending a POST request to /chat with a DialogueSnippet JSON object.

Endpoints

  • GET /: Root route that returns a welcome message.
  • GET /start: Starts a new conversation thread with the AI.
  • POST /chat: Sends a user's message to the AI and returns its response.

Debugging

The code includes print statements for debugging purposes. These will show up in your terminal as you interact with the API.

License

This project is licensed under MIT License. For more information, please see the LICENSE file.