Welcome to the Mohawk College Conversational Assistant! This is a FastAPI-based backend service designed to handle user queries about Mohawk College programs, student services, and more. It uses LangChain for Retrieval-Augmented Generation (RAG), OpenAI for text processing, and MongoDB for storing conversation history.
- Retrieval-Augmented Generation (RAG) using local documents for more accurate, context-specific answers.
- OpenAI GPT integration for query refinement and fallback responses.
- MongoDB Storage for logging user queries and responses.
- WebSocket Support for real-time interactive conversations.
- External Crawling to fetch content from Mohawk College or MSA websites when queries pertain to specific keywords.
- Prerequisites
- Project Setup
- Environment Variables
- Run the Application
- API Endpoints
- WebSocket Usage
- Database Integration
- Directory Structure
- Python 3.9+ (Recommended)
- pip or conda for installing Python packages
- MongoDB instance (local or remote)
- An OpenAI API key (for GPT-3.5-turbo or GPT-4 calls)
- Clone the repository:
git clone https://github.com/temi-t8/backend-server.git
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Linux/Mac
venv\Scripts\activate # On Windows- Install dependencies
pip install -r requirements.txt- 🔐 Environment Variables
export OPENAI_API_KEY=sk-proj
export MONGODB_URI="mongodb+srv://TEMI:robot@"NOTE: You can create your own MongoDB Cluster and add MongoDB URI but make sure to keep double inverted comma to avoid error
After installing all dependencies and setting your environment variables, you can start the server:
uvicorn app:app --host 0.0.0.0 --port 8000 --reloadThe application will be available at: http://localhost:8000
- Health Check
- Endpoint: GET /health
- Description: Returns the current status of the service and MongoDB connection.
- Response Example:
{ "status": "running", "version": "1.0.0", "db_status": "healthy" }
- Answer Query
-
Endpoint: POST /answer
-
Request Body:
{ "query": "What programs does Mohawk College offer related to Software?" } -
Response Example:
{ "answer": "Mohawk College offers the Computer Systems Technician – Software Development program..." } -
Description:
- Refines the user query for spelling or partial program names.
- Checks if the query relates to Mohawk programs, MSA, admissions, etc.
- Crawls official Mohawk/related sites for matching content or uses Local RAG from the data folder to generate an answer.
- If no context found, it uses a fallback with OpenAI GPT to provide a generic or playful response.
- Endpoint: GET /ws
- Protocol: WebSocket
This endpoint allows real-time conversational interaction:
- Connect to the WebSocket at ws://localhost:8000/ws.
- Send a message (the user query).
- Receive a text response.
Example (using websocat or similar CLI tool):
websocat ws://localhost:8000/ws
> Hello, what jokes do you know?
< Here's a fun one...The server will:
- Refine your query.
- Check if it’s a fun/joke request or a Mohawk-related query.
- Respond with either RAG-based or fallback content.
- Store the conversation in MongoDB.
NOTE: if this server is being deployed anywhere it should use secure websocket such as wss://domain/ws/
This service uses MongoDB to record each user query and the corresponding answer.
- Collection Name: ConversationTracker
- Stored Fields:
- query: The original user query.
- answer: The assistant’s answer.
- timestamp: DateTime of the stored record.
.
├── data/
│ ├── faqs.txt
│ └── ...
├── main.py
├── requirements.txt
├── .gitignore
└── README.mdIf you have any questions, reach out via email me at nevil-dineshkumar.patel@mohawkcollege.ca