MINDSDB: Integrate AI/ML models into your applications

🌟What is MindsDB?
MindsDB is a platform that simplifies model management and integrates existing AI models into applications with ease.
It covers various aspects of model management including creation, training, fine-tuning, and version control.We can …


This content originally appeared on DEV Community and was authored by Niharika Goulikar

🌟What is MindsDB?
MindsDB is a platform that simplifies model management and integrates existing AI models into applications with ease.
It covers various aspects of model management including creation, training, fine-tuning, and version control.We can also automate tasks in our AI workflows with MindsDB Jobs, or define and execute specific events with Triggers.

🟢Let's build an application in which we will learn how to integrate mindsDB into our application:-

🌟What is this application all about?
This application leverages MindsDB to deliver intelligent chat assistance and automatically categorize each post into specific categories. Users can view all posts, comment on them, like their favorites, and create new posts. The app uses token-based authentication to ensure secure access and interactions. Additionally, users have the ability to report posts, helping to maintain content quality and compliance with community standards.

🛠 TECH STACK:

  • Frontend: NextJs, Tailwind CSS
  • Backend: Next Js
  • Database: Postgres DB

📤 SETUP

  • Create a .evn file in the root level of your application and add these variables into it:
MINDSDB_KEY=<your api key>
MINDS_URL=<minds url>
BASE_URL=<application url>

🚀To get Api key from MindsDB follow these steps:
1.Go to https://mdb.ai/minds and create a new account if you don't have an existing account on MindsDB.
2.Go to the ApiKeys section and generate a new ApiKey and now you are good to go.

Mindsdb ApiKey generation page

  • BASE_URL is your application url which host the frontend (in our case since we are using nextJS, both frontend and backend will be hosted on the same url) and this is just to prevent cors error.You can bypass it by incorporating some workarounds.

  • MINDS_URL We will get this URL from the MindsDB Docker instance that we will start shortly.

☘ Since we are dealing with integration of mindsDB into our application. There are many ways to integrate mindsDB into our application.Few of them are:

  • SQL APIs
  • REST APIs
  • Docker In this example we are going to use MindsDB Docker image to create models. To create mindsDB docker instance run this command:
docker run --name mindsdb_container -p 47334:47334 mindsdb/mindsdb

🚀Go the editor router of that docker container url and you will see this(P.S: the image attached has models predefined but you need to create models on your own)

MINDSDB docker image

🚀 How to create models?
Creating a model in MindsDB is as easy as writing a prompt(because all you have to do is just write a prompt 😆).

  • But before creating model we have to create an engine which will run our models.
CREATE ML_ENGINE engine_name
FROM handler_name
USING
  api_key_name = 'your-api-key-value';

Here we are going to use apiKey that we just generated.
🍀Creating models

CREATE MODEL model_name
PREDICT column_name
USING
    engine = 'engine_name',
    prompt_template = 'Your prompt here: {{variable}}';

Here,

  • column_name this is the variable which will contain the response for your input.
  • {{variable}} this is your input.
  • 'engine_name' replace this the engine that you create.

🍀Writing prompt:-
We can write prompts to accomplish almost any task, though there are some limitations.
With one such prompt being present in the image below:

Prompt example

Now that we have defined our models,we need use these models in our application.We will create Api endpoints, so that our frontend can talk to these models
🍀Example of one such endpoint:

import client from "@/db";
import { NextRequest, NextResponse } from "next/server";

interface Body {
  query: string;
}

export async function POST(req: NextRequest) {
  try {
    // Parse request body
    const request: Body = await req.json();

    const response = await fetch(
 `${process.env.MINDS_URL}/api/projects/mindsdb/models/blog_helper/predict`,
      {
        method: "POST",
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${process.env.MINDSDB_KEY}`  // Replace with your actual API key
        },
        body: JSON.stringify({
          data: [{ query: request.query }]
        })
      }
    );

    const newPost = await response.json();

    return NextResponse.json({ response: newPost, status: 200 });
  } catch (error: any) {
    console.error("Error processing request:", error);
    return NextResponse.json({ message: "Internal server error", status: 500 });
  }
}




Now our frontend can talk to these models we have created.

This is the project that I'm referencing to:
BLOGGO

Here a video demonstration of the project:
Loom video link

I hope you enjoyed this short tutorial on MindsDB.Stay tuned for more such interesting and concise tutorials!

Hope to see you all in the next one,

Niharika.


This content originally appeared on DEV Community and was authored by Niharika Goulikar


Print Share Comment Cite Upload Translate Updates
APA

Niharika Goulikar | Sciencx (2024-08-28T11:13:38+00:00) MINDSDB: Integrate AI/ML models into your applications. Retrieved from https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/

MLA
" » MINDSDB: Integrate AI/ML models into your applications." Niharika Goulikar | Sciencx - Wednesday August 28, 2024, https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/
HARVARD
Niharika Goulikar | Sciencx Wednesday August 28, 2024 » MINDSDB: Integrate AI/ML models into your applications., viewed ,<https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/>
VANCOUVER
Niharika Goulikar | Sciencx - » MINDSDB: Integrate AI/ML models into your applications. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/
CHICAGO
" » MINDSDB: Integrate AI/ML models into your applications." Niharika Goulikar | Sciencx - Accessed . https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/
IEEE
" » MINDSDB: Integrate AI/ML models into your applications." Niharika Goulikar | Sciencx [Online]. Available: https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/. [Accessed: ]
rf:citation
» MINDSDB: Integrate AI/ML models into your applications | Niharika Goulikar | Sciencx | https://www.scien.cx/2024/08/28/mindsdb-integrate-ai-ml-models-into-your-applications/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.