Webbie - Create Bots from Your Data using MindsDB in minutes !

Amit WaniAmit Wani
6 min read

Introduction

Hey, In this day and age of AI, we all want an assistant that will solve our specific problems. There have been many Large Language Models that solve generic problems and provide answers to them. But there's still a gap for tools where you can get answers just for your data. This is where the idea of Webbie comes in.

Webbie - https://webbie.amitwani.dev is a simple tool, where you can create an AI bot in minutes, based on your provided information. This chat-based interface is swiftly generated using MindsDB in the backend, offering a personalized solution to users' unique needs.

Tech Stack

  1. Backend - Powered by NodeJS and Express.

  2. Frontend - Developed using Angular.

  3. Database - Utilizes PostgreSQL.

  4. Tools - Leverages MindsDB for machine learning capabilities.

  5. ML Engine - Employs LlamaIndex and Langchain for robust machine learning.

  6. Deployment - Utilizes Docker, DigitalOcean, and NorthFlank for efficient deployment.

Installation

Backend - The NodeJS server operates on a DigitalOcean droplet using forever start server.js.

Frontend - The Angular application runs in a NorthFlank container, employing a Docker image with Nginx Reverse Proxy.

Database - PostgreSQL operates on a DigitalOcean droplet as a service.

Tools - MindsDB is hosted on a DigitalOcean droplet using python -m mindsdb.

Components

Data Sources

Webbie supports three data sources (with potential for more in the future):

  1. Text Data - Simple textual information.

  2. CSV File - A CSV file containing row/column-based data.

  3. Website Link - Any website link with pertinent information.

ML Engine

I have used llama_index handler from MindsDB to create an ML ENGINE first in the MindsDB.

CREATE ML_ENGINE llamaindex
FROM llama_index

OpenAI

You will have to provide an OpenAI API Key to create the bot. This key is not stored in our database.

Model

After providing the above details along with the bot name and bot description. Our middleware server built on NodeJS and Express will send queries to MindsDB for creating appropriate models.

I have used llama_index for this model and a SimpleWebPageReader reader of llama_index

Now backend will create the model in MindsDB using a query like this -

CREATE MODEL abc
PREDICT answer
USING
engine = 'llamaindex',
index_class = 'GPTVectorStoreIndex',
reader = 'SimpleWebPageReader',
source_url_link = 'https://blog.amiwani.dev',
input_column = 'question',
openai_api_key = '<api-key>';

Here source_url_link will be changed depending on the data source. Below is an explanation of how it is generated and used.

Website Data Model

This was the easiest to do, as the user-provided URL can be directly passed to the model in the source_url_link.

CREATE MODEL abc
PREDICT answer
USING
engine = 'llamaindex',
index_class = 'GPTVectorStoreIndex',
reader = 'SimpleWebPageReader',
source_url_link = 'https://blog.amiwani.dev',
input_column = 'question',
openai_api_key = '<api-key>';

Text Data Model

For Textual Data, since the llama_index handler does not support text data out of the box, we create a text file and upload it to the server with the data input from the user. And then URL of that text file is provided to the model in the source_url_link

CREATE MODEL abc
PREDICT answer
USING
engine = 'llamaindex',
index_class = 'GPTVectorStoreIndex',
reader = 'SimpleWebPageReader',
source_url_link = 'http://<server>/api/file/download/<filename>.txt',
input_column = 'question',
openai_api_key = '<api-key>';

CSV File Data Model

For CSV File Data, since the llama_index handler does not support text data out of the box, we upload the CSV File to the server. And then URL of that text file is provided to the model in the source_url_link

CREATE MODEL abc
PREDICT answer
USING
engine = 'llamaindex',
index_class = 'GPTVectorStoreIndex',
reader = 'SimpleWebPageReader',
source_url_link = 'http://<server>/api/file/download/<filename>.csv',
input_column = 'question',
openai_api_key = '<api-key>';

Slack

You can also enable Slack notifications in a channel. You will receive notifications in a channel for every question asked to the bot along with the answer given by the bot.

You can add your Slack App Token and Slack Channel Name to enable notifications. This app token is not stored in our database.

To obtain slack app token you can go to this guide

When the Slack notifications are enabled:

Create Slack Database

We will create a Slack database connection in the MindsDB as below:

CREATE DATABASE my_slack
WITH
  ENGINE = 'slack',
  PARAMETERS = {
      "token": "<slack-token>"
    };

Create JOB

We will create a JOB in MindsDB that will run every minute and send notification for every question asked to the bot:

CREATE JOB job AS (
INSERT INTO my_slack.channels(channel, text)
SELECT
   "<channel-name>" as channel,
   message as text
FROM psql_datasource.transcript
WHERE createdAt > "{{PREVIOUS_START_DATETIME}} AND botId = "<bot-id>"
) EVERY MINUTE;

This Job will read from transcript table in our PostgreSQL database for latest messages for this bot using PREVIOUS_START_DATETIME and botId and then send them in the appropriate Slack channel.

Workflow

The user will log in to Webbie - https://webbie.amitwani.dev

Create a Bot and Model

Frontend

The user will create a bot by providing below details -

  1. Bot Name

  2. Bot Description

  3. Select Data Source - Text/CSV/Website

  4. OpenAI API Key

  5. Enable Slack Notifications (optional)

    1. Slack App Token

    2. Slack Channel Name

Backend

  1. The bot details will be verified

  2. Files will be uploaded if required

  3. CREATE MODEL using MindsDB as explained above

  4. CREATE SLACK DATABASE using MindsDB as explained above if required

  5. CREATE JOB using MindsDB for Slack Notifications as explained above if required

  6. When the Model is Successfully generated, send a bot link to the client

Chat with the Bot

Any user can open the bot's chat interface by going to the link https://webbie.amitwani.dev/bot/<bot-id>

Frontend

  1. Users can interact with the bot.

  2. The query will be sent to the backend and the response will be shown to the user

Backend

  1. The query will be sent to Model for prediction using MindsDB as below:
SELECT answer FROM modelName WHERE question = 'question'
  1. The answer will be sent to the client.

  2. Question and answers will be stored in the transcript table

  3. Slack notification will also be sent in the channel if enabled using MindsDB as below:

Future Scope

Several features can be incorporated in the future:

  1. Support for More Data Sources: Expand support for additional file types such as PDF/XLSX/DOCX.

  2. Database Connection Support: Allow users to add actual database connections for bot data.

  3. User Management System: Implement a user management system for enhanced control.

  4. Notification Integration: Integrate more notification channels like Microsoft Teams, Twilio, etc.

You are invited to collaborate on the GitHub -

Conclusion

The development of Webbie provided a valuable learning experience, exploring diverse tech stacks and leveraging MindsDB. This project reflects a journey of exploration, experimentation, and innovation.

This is my submission for the MindsDB x Hashnode Hackathon.

1
Subscribe to my newsletter

Read articles from Amit Wani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amit Wani
Amit Wani

๐—ช๐—”๐—ฅ๐—ฅ๐—œ๐—ข๐—ฅ! Full Stack Developer | SDE Reliance Jio ๐Ÿ–ฅ๏ธ Tech Enthusiastic ๐Ÿ’ป Man Utd ๐Ÿ”ด Sachin & Dravid fan! โšพ Photography ๐Ÿ“ธ Get Hands Dirty on Keyboard!