This project is an example of integrating the QuikChatJS widget with a Python FastAPI webbackend. The application includes endpoints for handling both completions and streaming completions from an API like OpenAI's GPT, as well as a chat widget that can be embedded in other applications.
/examples/FastApi-Quikchat-Starter
|--- app.py # Main FastAPI application
|--- static/
| |-- index.html # Main chat page
| |-- widget.html # Embeddable chat widget page
| |-- quikchat.css # QuikChatJS CSS
| |-- quikchat.umd.min.js # QuikChatJS JavaScript
|-- .env # Environment variables
|-- README.md # This documentation
|-- requirements.txt # Python dependencies
Install dependencies:
pip install -r requirements.txt
Set up environment variables:
Create a .env
file in the root of the project with the following content:
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_API_KEY=your_openai_api_key_here
Replace your_openai_api_key_here
with your actual OpenAI API key.
To start the FastAPI server, run:
python main.py
The server will start on http://127.0.0.1:8000
.
Then go to your browser and open up http://127.0.0.1:8000.
/
: Serves the main chat page./widget
: Serves quikchat as an embeddable chat widget page./api/completion
: POST endpoint for fetching a completion response./api/completion-history
: POST endpoint for fetching a completion response using full message history./api/streaming-completion
: POST endpoint for streaming a completion response./api/streaming-completion-history
: POST endpoint for streaming a completion response with full message history.Main Chat Interface: Access the main chat interface by navigating to http://127.0.0.1:8000/
in your browser.
Embeddable Widget: Access the embeddable widget by navigating to http://127.0.0.1:8000/widget
.
While the server is running, any changes you make to the main.py
or static files will be automatically reloaded.