Introduction
In this blog post, we present how to create OpenAI models within MindsDB. In this example, we ask a model to provide a summary of a text. The input data is taken from our sample MongoDB database.Prerequisites
To follow along, install MindsDB locally via Docker or Docker Desktop.How to Connect MindsDB to a Database
We use a collection from our MongoDB public demo database, so let’s start by connecting MindsDB to it. You can use Mongo Compass or Mongo Shell to connect our sample database like this:Tutorial
In this tutorial, we create a predictive model to summarize an article. Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example:Note that you need to create an OpenAI engine first before deploying the OpenAI model within MindsDB.Here is how to create this engine:
insertOne method triggers MindsDB to generate an AI collection called text_summarization that uses the OpenAI integration to predict a field named highlights. The model is created inside the default mindsdb project. In MindsDB, projects are a natural way to keep artifacts, such as models or views, separate according to what predictive task they solve. You can learn more about MindsDB projects here.
The training_options key specifies the parameters that this handler requires.
- The
engineparameter defines that we use theopenaiengine. - The
prompt_templateparameter conveys the structure of a message that is to be completed with additional text generated by the model.
Follow this instruction to set up the OpenAI integration in MindsDB.
insertOne method has started execution, we can check the status of the creation process with the following query:
articles collection is used to make batch predictions. Upon joining the text_summarization model with the articles collection, the model uses all values from the article field.