Starter for ChatBot APIs, created using the Express Mongo API starter. With chatbot functionalities added on top.
- Go to MongoDB Cloud and sign in using the credentials from Mega.
- Create a new project.
- Inside your new project, create a cluster.
- Having your new cluster selected, click "Browse collections" in the same panel as the selected cluster.
- Create a new database and a new collection. (name examples:
testfor database andknowlegde_basefor collection) - In your new collection, go to Atlas Search.
- Create Search Index, select the newly created database, Type: Atlas Search, Index Name: default, Configuration: JSON Editor and paste the following object:
{
"mappings": {
"fields": {
"embedding": {
"dimensions": 1536,
"similarity": "cosine",
"type": "knnVector"
},
"tag": {
"type": "token"
}
}
}
}
- Create another Search Index, Type: Vector Search, Index Name: vector_index, Configuration: JSON Editor and paste the following object:
{
"fields": [
{
"numDimensions": 1536,
"path": "embedding",
"similarity": "cosine",
"type": "vector"
}
]
}
Refer to the examples folder for code examples regarding controllers, models, routes and seeds for "to do" items.
Install dependencies
npm ciCopy the example environment variables
cp .env.example .envOptional: Add seeds to your Mongo database
npm run seedStart the local server
npm run dev| Variable Name | Description |
|---|---|
| MONGODB_ATLAS_URI | The connection string to the cluster |
| MONGODB_ATLAS_DB_NAME | Name of the database inside the cluster |
| MONGODB_ATLAS_COLLECTION_NAME | The name of the collection where the bot's knowledge is stored |
| OPENAI_API_KEY | API key for the OPENAI API, used for operations involving ChatGPT |
| HEYGEN_API_KEY | API key for Heygen API, used for generating the chatbot's talking avatar |
This script is used for scraping data from a .pdf file and save it to a JSON file in the data folder. This data can be inserted into the database using the add-documents script. Refer to the next entry on how it works. This script can be run by using the following command:
node ./scripts/pdf-to-docs.js
This script is used for inserting documents into the chatbot's knowledge base. Make sure you have your .json file in your data folder and that it corresponds with the filename in the code. It can be run by using the following command:
node ./scripts/add-documents.js
Important features are listed below
You can use the automatic soft delete feature for any collection in the MongoDB database.
This feature will backup the entire deleted document and prevent it from being permanently deleted.
JSON web tokens (JWT) and HTTP-only cookies are used to facilitate authentication.
You can use the common integrations from the plugins folder: AWS, Netopia, Postmark and Smartbill.
Each common integration has an extensive documentation, code samples and step-by-step instructions.
You can append these query params to any route in this API:
- use
&test=loading&wait=5000to delay any request with 5 seconds - use
&test=errorto trigger a failed request
Customize the loading time with the wait query param which takes the number of miliseconds you want to wait.
This feature is available only for dev environments.
You should use the Recaptcha middleware on any public route. Moreover, you should skip Recaptcha middleware and validation on any private route.
By default Recaptcha will not be enabled when the request has no origin (it is sent through an API).
You can use the Postman collection from the postman folder to explore the API and its routes.