Automate notifications about incoming customer reviews
This tutorial presents how to chain OpenAI models within MindsDB to analyze text sentiment and generate responses, which will be sent in the form of Slack notifications.
+----------------------------+-----------------------------+------------------------+| created_at | product_name | review |+----------------------------+-----------------------------+------------------------+| 2023-11-08 17:23:21.028485 | Power Adapter | It is a great product. || 2023-11-08 17:23:21.028485 | Bluetooth and Wi-Fi Speaker | It is ok. || 2023-11-08 17:23:21.028485 | Kindle eReader | It doesn’t work. |+----------------------------+-----------------------------+------------------------+
CREATE MODEL sentiment_classifierPREDICT sentimentUSING engine = 'openai_engine', model_name = 'gpt-4', prompt_template = 'describe the sentiment of the reviews strictly as "positive", "neutral", or "negative". "I love the product":positive "It is a scam":negative "{{review}}.":';
INSERT INTO customer_reviews_slack_app.channels (channel, text)VALUES("customer-reviews", "Testing Slack connection");
Create a job to send notification every time a negative review is received.
Copy
Ask AI
CREATE JOB customer_reviews_notifications ( INSERT INTO customer_reviews_slack_app.channels (channel, text) SELECT "customer-reviews" as channel, concat('Product: ', input.product_name, chr(10), 'Received negative review at: ', input.created_at, chr(10), 'Review: ', input.review) as text FROM local_postgres.demo.amazon_reviews AS input JOIN sentiment_classifier AS output WHERE input.created_at > LAST AND output.sentiment = 'negative')EVERY 1 minute;
These commands are used to monitor the job.
Copy
Ask AI
SELECT * FROM jobs WHERE name = 'customer_reviews_notifications';SELECT * FROM jobs_history WHERE name = 'customer_reviews_notifications';
Create a job to send notification, including a sample response, every time a positive review is received.
Copy
Ask AI
CREATE JOB customer_reviews_and_reponses_notifications ( INSERT INTO customer_reviews_slack_app.channels (channel, text) SELECT "customer-reviews" as channel, concat('---------', chr(10), 'Product: ', input.product_name, chr(10), 'Received ', input.sentiment, ' review at: ', input.created_at, chr(10), 'Review: ', input.review, chr(10), 'Sample response: ', output.response) as text FROM (SELECT inp.created_at AS created_at, inp.product_name AS product_name, inp.review AS review, outp.sentiment AS sentiment FROM local_postgres.demo.amazon_reviews AS inp JOIN sentiment_classifier AS outp WHERE inp.created_at > LAST) AS input --'2023-10-03 16:50:00' AND inp.created_at > "{{PREVIOUS_START_DATETIME}}" JOIN response_model AS output WHERE input.sentiment = 'positive';)EVERY 1 minute;
These commands are used to monitor the job.
Copy
Ask AI
SELECT * FROM jobs WHERE name = 'customer_reviews_and_reponses_notifications';SELECT * FROM jobs_history WHERE name = 'customer_reviews_and_reponses_notifications';
Use this command to disable the job.
Copy
Ask AI
DROP JOB customer_reviews_and_reponses_notifications;