Exercise: Sentiment Score
Your objective determines how you should build in Less
In this exercise, you’ll work with OpenAI to generate product reviews score with artificial intelligence. It can sound complex but the intention with the exercise is to show you how easy anyone can begin creating value with AI. We only use 10 tools to complete this exercise.
You’ll learn tool such as API, Text Column and Parse Data
There are hints to help you get through this exercise. You can also download our solution model and import it in your own model. The file are available at the end of this page.
Context
AI is currently very topical in the data space but it can be difficult to operationalize. We’re going to do that in this exercise. The exercise is about generating a review score column with OpenAI. You’re going to be working with Amazon Tap product reviews. This exercise is relatively simple in terms of the number of actions you’ll be using. The purpose is to build confidence in using the API action and showing how easy it is to start building with AI.
This exercises involves setting up an OpenAI account. Before you worry about costs, the workflow you’ll end up building cost approx. 0.0015USD to run.
Data
Create a new connection. Search for “exercise” and select the AI-Driven Product Review. Configure the connector and you should have access to the tables from the Canvas.
API Basics
APIs are a method for computers to interact with each other (read more here). In this exercise, we’re going to be interacting with OpenAI’s computers from the inside the Less canvas. The is a very flexible and customizable functionality that opens up a bunch of use cases.
There are many types of API methods (GET, POST, PUT, DELETE, etc). You can think of this as different way of interacting. A GET API call asks the other computer to return some data - you might call Mailchimp’s API to return all your campaigns with a GET call. POST calls - which we will use - asks the other computer to generate something. For instance, you might use a POST call to ask OpenAI to generate an AI review score. You could also use POST calls to create new members in Mailchimp.
You need to configure a couple of things when using API calls. In almost all methods, you need a t l e a s t three components:
- Method. As discussed above; GET, POST, PUT, DELETE
- URL. This describes what you want the computer do do (for instance GET
/lists/{list_id}/members
to get all your members in the list corresponding to list_id) - Authentication. You need to inform the other computer who you are. Think of this as a key to opening a door.
OpenAI API Structure
We’ll be working with a POST API call to OpenAI. You will call using a POST call to the https://api.openai.com/v1/chat/completions
URL with an
Authorization bearer token. You will also add a body which
tell the computer what to create for you.
The body consist of two things specific to OpenAI. This will be familiar if you used ChatGPT. We’re sending a prompt to OpenAI along with some input which in our case is the review data from Amazon.
To the right, you’ll see how this is configured in the API action inside Less. You’ll see that we are referencing columns in Step #3 and #5 (e.g. [token]). In other words, we have a column that contains our authorization bearer token.
The API action on the Less canvas works by sending one API call per row in the dataset. As a result, it will take some time to run the model - e.g. if you have 10.000 rows, you will send 10.000 API calls (which takes time). It’s a good idea to use a Limit action before the API tool while you’re testing to avoid sending too many calls.
You need to create an account and bearer token at OpenAI. Go to https:/ /openai.com/ and create an account. Go to API once you’ve logged in. Once you’re logged in, navigate to Settings and API Keys. Hit the “Create new secret key” and make sure you store the key.
You also need to add funds to OpenAI. You can do that through Settings → Billing → “Add credit balance”. One call with all 30 rows in the reviews dataset costs around 0.0015USD per run. During the entire testing phase while we built this exercise, we spent a total of 0.05USD. So you shouldn’t worry about pricing (unless you start calling the API with millions of rows of data regularly…).
Task
You’re given a dataset with 30 rows. One of the columns is called review_text. This is the one we ask OpenAI to score from 1-10. In a real-life scenario, you might imagine looking the low-scoring reviews to better understand client frustration. Are they frustrated about packaging? Delivery? Features? Pricing? You could also experiment with doing this with OpenAI…
You need to come up with a prompt for OpenAI. We used the one below, but you can experiment with what works for you. To parse the result from OpenAI, you should take a look at the Parse JSON action.
If you need any help from us, please reach out through the in-app support in the bottom, right-hand corner.
Less Prompt
You are to evaluate the product reviews data on a scale from 0-10 where 10 is an absolute fantastic review and 1 is a horrible review. The product is a bluetooth speaker called Amazon Tap. ONLY OUTPUT AN INTERGER NUMBER BETWEEN 1 AND 10 (inclusive).
The table below is the result. We built it with 15 tools. The AI_review_score column is the one we created with AI.
Hints
Solution File
Download the solution file here and see how to import it below. Remember to import it in a new model.