In this tutorial, we’ll analyze sentiment of Intercom conversations. We’ll use Airbyte to extract data from Intercom and store it into a Google BigQuery database. Then, we’ll make this data available to MindsDB, create and deploy a GPT model within MindsDB, and join both data and a model to predict the sentiment values to be further analyzed in business analytics tools.

Data Setup

We use Airbyte to pull data from Intercom and load it into a Google BigQuery database.

You can try Airbyte Cloud or use the Airbyte Open Source version.

Follow this video or this detailed tutorial to learn how to pull conversation data from Intercom and load it into a Google BigQuery database using Airbyte and visualize it using Metabase analytics.

Connecting a Database

Now you can connect the Google BigQuery database that stores the Intercom data to MindsDB.

   engine = "bigquery",
   parameters = {
      "project_id": "bgtest-1111",
      "dataset": "mydataset",
      "service_account_keys": "/tmp/keys.json"

Follow this instruction to connect your database to MindsDB.

Creating a model

Let’s create a GPT model that we’ll use to predict sentiment of Intercom conversations.

Before creating an OpenAI model, please create an engine, providing your OpenAI API key:

CREATE ML_ENGINE openai_engine
FROM openai
	openai_api_key = 'your-openai-api-key';
CREATE MODEL sentiment_classifier_model
PREDICT sentiment
    engine = 'openai_engine',
    model_name = 'text-davinci-003',
    prompt_template = 'describe the user sentiment from the following conversation STRICTLY as positive or neutral or negative.\n###\n{{full_conversation}}     \n###\nSentiment [positive/neutral/negative]:';

Here is how we can check its status:

DESCRIBE sentiment_classifier_model;

Once the status is complete, we can proceeed to make predictions.

Making batch predictions

Now we join our data table (joined_conversations) that stores Intercom conversations with the model (sentiment_classifier_model) created in MindsDB. That’s how we can make batch predictions for all conversations at once.

        -- joined_conversations.full_conversation,


    -- data table that stores conversations
        -- using native bigquery syntax
        SELECT * FROM bqdataset (
            STRING_AGG(p.body, "\n" ORDER BY p.created_at ASC LIMIT 15) AS full_conversation,
            FROM conversation_parts p
            JSON_VALUE(, '$.type') = 'user'
            GROUP BY conversation_id LIMIT 10
    ) AS joined_conversations


    -- model that analyzes sentiment
    sentiment_classifier_model AS sentiments;

Run it in the MindsDB editor to find out the output.

What’s Next?

Want to learn more about MindsDB? Check out these resources: