This project assignment includes two programs: a Python API and a Node.js API. The Python API uses one of two large language models to answer questions. The Node.js API is the public interface that users interact with.
-
Python API: Python 3.12
- This is a private API that uses models like Llama2 and Mistral to generate answers & saves conversation history in a MongoDB database.
-
Node.js API: Node v20
- This is the public API that sends user queries to the Python API & retrieves and returns the conversation history from the Python API.
- The Node.js API selects a model & receives a query from the user.
- It sends this query to the Python API to generate a response using the selected model.
- The Python API saves the query and response in MongoDB & sends the response back to the user.
- The MongoDB database stores conversation history.
- Each entry includes:
- User query
- Model response
- Timestamp of the conversation
- The Python API is not exposed to the public. Only the Node.js API is public.
- This helps protect the models and database from direct access.
- Input validation is in place to prevent empty queries and other issues.
- You need a huggingface token with access to inference to use the models
- The safe tensors that will be downloaded from huggingface are >14GB per model
- The program will run considerably slowly on CPUs ( >~5 mins/request)
-
Select Model
- Endpoint:
POST /api/select_model - Body:
{ "model": "llama2" // or "mistral" } - Description: Selects the model to use for queries.
- Endpoint:
-
Send Query
- Endpoint:
POST /api/query - Body:
{ "query": "Your question here" } - Description: Sends a query to the selected model and gets a response.
- Endpoint:
-
Get Conversation History
- Endpoint:
GET /api/history - Description: Retrieves all conversation history, ordered by date (most recent first).
- Endpoint:
-
Get Specific Conversation
- Endpoint:
GET /api/conversation/:id - Description: Retrieves details of a specific conversation by ID.
- Endpoint:
- Docker packages both applications and their dependencies to ensure that the APIs run in the same environment on any machine. This makes it easy to build and run the applications together.
- Build the Docker Containers:
docker-compose up --build