A Proof of Concept (PoC) that leverages websockets and HTTP streaming to relay OpenAI's GPT chat completions in real-time using the FastAPI framework. While FastAPI is used here, any API framework supporting websockets and HTTP streaming can be adapted for this purpose.
If you prefer to set up your local environment without using Docker, you can follow these steps:
-
Create a Virtual Environment:
python3 -m venv .venv
Activate the Virtual Environment:
-
For macOS and Linux:
source .venv/bin/activate
-
For Windows:
.venv\Scripts\activate
-
-
Install the Dependencies:
Ensure you're inside the project directory and your virtual environment is activated.
pip install -r requirements.txt
-
Run the Application:
uvicorn main:app --reload
This will start the FastAPI application with hot-reloading enabled. You can access the application at
http://localhost:8000
.
-
Build the Docker Image:
From the project root, execute:
docker build -t app .
-
Run the Container:
docker run -d -p 8000:8000 app
The application will be available at:
http://localhost:8000
.
FastAPI development is made smoother with hot-reloading. I have added a dedicated Dockerfile.dev
for this.
-
Build the Development Image:
From the project root, execute:
docker build -f Dockerfile.dev -t app-dev .
-
Run the Container with Volume Mount:
This mounts the current project directory to the container, allowing you to observe changes in real-time:
docker run -p 8000:8000 -v $(pwd):/app app-dev
Navigate to
http://localhost:8000
. Any source code modifications will instantly reflect in the application.