01-SQL-AI-Functions-Introduction(Python)

Loading...

Actioning Customer Reviews at Scale with Databricks SQL AI Functions

AI Functions are built-in Databricks SQL functions, allowing you to access Large Language Models (LLMs) directly from SQL.

Popular LLMs such as the one provided by OpenAI APIs let you apply all sort of transformations on top of text, from classification, information extraction to automatic answers.

Leveraging Databricks SQL AI functions AI_GENERATE_TEXT(), you can now apply these transformations and experiment with LLMs on your data from within a familiar SQL interface.

Once you have developed the correct LLM prompt, you can quickly turn that into a production pipeline using existing Databricks tools such as Delta Live Tables or scheduled Jobs. This greatly simplifies both the development and productionization workflow for LLMs.

AI Functions abstracts away the technical complexities of calling LLMs, enabling analysts and data scientists to start using these models without worrying about the underlying infrastructure.

Increasing customer satisfaction and churn reduction with automatic reviews analysis

In this demo, we'll build a data pipeline that takes customer reviews, in the form of freeform text, and enrich them with meaning derived by asking natural language questions of Azure OpenAI's GPT-3.5 Turbo model. We'll even provide recommendations for next best actions to our customer service team - i.e. whether a customer requires follow-up, and a sample message to follow-up with

For each review, we:

  • Determine sentiment and whether a response is required back to the customer
  • Generate a response mentioning alternative products that may satisfy the customer

 

1/ Setup: get your Open AI configuration and save key as Databricks secret

Prerequisites

In order to run this demo in your own environment you will need to satisfy these prerequisites:

  • Enrolled in the Public Preview. Request enrolment here
  • Access to a Databricks SQL Pro or Serverless warehouse
  • An Azure OpenAI key
  • Store the API key in Databricks Secrets (documentation: AWS, Azure, GCP).

Setting up Open AI

In order for AI_GENERATE_TEXT() to call your Azure OpenAI model, you need to provide the key to your Azure OpenAI resource endpoint. We'll explore how we retrieve this information and store it secure in Databricks secrets.

Open the 02-Create-OpenAI-model-and-store-secrets to see how to setup your Open AI service and retrieve its configuration.

2/ AI_GENERATE_TEXT introduction: Generating fake data for our demo with Open AI

To start our demo, we will leverage AI_GENERATE_TEXT() to generate fake reviews to use in our data pipeline.

The sample data mimics customer reviews for grocery products submitted to an e-commerce website, and we will craft a prompt for Open AI to generate this data for us.

Open the 03-Generate-fake-data-with-AI-functions to start with your first SQL AI Function!

4/ Building our SQL pipeline with Open AI to extract review sentiments

We are now ready to use create our full data pipeline:

 

Open the 04-automated-product-review-and-answer to process our text using SQL and automate our review answer!

Further Reading and Resources