This is a backend component that facilitates interaction with LLMs (OpenAI GPT-4o-mini). It provides:
- CRUD operations for conversations containing queries and responses.
- LLM query handling with conversation history as context.
- Anonymized query storage in MongoDB for auditing.
- REST API with OpenAPI docs for easy integration.
✅ FastAPI-based backend
✅ MongoDB for conversation storage
✅ Dockerized environment
✅ CRUD endpoints for managing conversations
✅ Send prompt queries & receive LLM responses
✅ Automatic logging & anonymization of chat history
✅ OpenAPI documentation for API usage
| Component | Technology |
|---|---|
| Backend | FastAPI (Python 3.10+) |
| Database | MongoDB (via Docker) |
| ORM | Beanie (MongoDB ODM) |
| LLM API | OpenAI Python Client |
| Validation | Pydantic |
| Containerization | Docker, Docker Compose |
git clone https://github.com/your-repo-name.git
cd your-repo-nameDuplicate the .env.example file and name it .env.
It should look like the following:
MONGO_URI="mongodb://mongo:27017/launchpad_db"
OPENAI_API_KEY="INPUT YOUR OPENAI API KEY HERE"Enter your OpenAI API Secret key as a string ✅ Notes:
- mongo is the service name inside Docker Compose.
- Do not use localhost inside Docker Compose (use mongo instead).
To build and start both FastAPI & MongoDB, run:
docker-compose up -d --build✅ Notes:
- d → Runs in detached mode (in the background).
- -build → Ensures FastAPI is rebuilt.
Check running containers:
docker psTo check if MongoDB is working inside the Docker container, enter:
docker exec -it mongodb mongoshThen, inside MongoDB shell:
show dbs # List databases
use launchpad_db # Switch to project database
show collections # Show collectionsIf the two containers are running correctly, you should be able to access:
API Documentation (Swagger UI): http://localhost:8000/docs
You can test the endpoints here. Enter the request body and view the response body.
The endpoints were created based off the openai.yaml file provided by the team.
POST /conversations/Example Request Body:
{
"name": "My Conversation",
"params": {
"temperature": 0.7
}
}Example Response:
{
"id": "656a21fb3b3f76f3a2e6b1c3",
"name": "My Conversation",
"params": {"temperature": 0.7}
}GET /conversations/Example Response:
[
{
"id": "656a21fb3b3f76f3a2e6b1c3",
"name": "My Conversation",
"params": {
"temperature": 0.7
}
},
{
"id": "656a21fb3b3f76f3a2e6b1c4",
"name": "Another Conversation",
"params": {
"temperature": 0.5
}
}
]GET /conversations/{conversation_id}Example Response:
{
"id": "656a21fb3b3f76f3a2e6b1c3",
"name": "My Conversation",
"params": {
"temperature": 0.7
},
"tokens": 100,
"pinned": false,
"prompts": [
{"role": "user", "content": "Hello!"},
{"role": "assistant", "content": "Hi, how can I assist you?"}
],
"modifications": {}
}Error Response:
{
"detail": {
"code": 404,
"message": "Specified resource(s) was not found"
}
}PUT /conversations/{conversation_id}Example Request Body:
{
"name": "Updated Conversation",
"params": {
"temperature": 0.9,
"max_tokens": 200
}
}Example Response:
{
"id": "656a21fb3b3f76f3a2e6b1c3",
"name": "Updated Conversation",
"params": {
"temperature": 0.9,
"max_tokens": 200
}
}DELETE /conversations/{conversation_id}POST /conversations/{conversation_id}Example Request Body:
{
"content": "Hello, how are you?"
}Example Response:
{
"message": "I'm doing well, thank you!"
}Stop the running contaainers
docker-compose downRestart the application
docker-compose up -d/your-repo
│── /app # FastAPI source code
│ ├── main.py # FastAPI entry point
│ ├── models/ # Pydantic models
│ ├── routes/ # FastAPI endpoints
│ ├── config/ # MongoDB connection
│── Dockerfile # FastAPI Docker setup
│── docker-compose.yml # Docker Compose for MongoDB + FastAPI
│── requirements.txt # Python dependencies
│── .env # Environment variables
|── .env.example # Example of .env file
|── .gitignore # Contains untracked file names
│── README.md # This file
Error: Port 27017 is already allocatedOpen docker terminal and enter this command to see the running containers:
docker psCheck the name of the container that is running on Port 27017.
docker stop <name of container>Then restart by running
docker-compose up -d