Use Azure OpenAI to filter support requests based on the language/tone of the email

I asked myself, can Azure OpenAI understand the tone of the text I am inputting? Turns out it can! Here is an example of the inputs I tested out. It can differentiate between for example if the text is neutral, positive, or negative.

What can we do with this? As a proof of concept I am creating a flow that can sort incoming support emails based on the tone of the language. We are going to move the emails into folders named Positive, Negative, and Neutral.

First of all, we need an API Key from Azure OpenAI. You can read about how you get that under the API Key header in my previous blog post, I wrote about “Getting started with Azure OpenAi and PowerShell“.

Next, we need to prepare the mailbox we are using, by creating the folders we are moving emails into.

Open Outlook web, and click “Create new folder”.

Enter the name and click Save. You need one for Positive, Negative, and Neutral.

Now got to flow.microsoft.com and create a new Automated Cloud Flow that is triggered by “When a new email arrives”.

Make sure you are authenticated with the user of the mailbox. (This is just a POC, you would rather use a shared mailbox in a real live scenario).

Click New Step.

Add an HTTP action

Enter the settings like below:

URI:
(the URI contains your Azure OpenAI resource name and deployment name)

Body:

{
"prompt": "Is the following text possitive, negative or neutral? ",
"max_tokens": 2000
}
view raw body.txt hosted with ❤ by GitHub

Add a Parse JSON action.

Add the following Schema:

{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"object": {
"type": "string"
},
"created": {
"type": "integer"
},
"model": {
"type": "string"
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string"
},
"index": {
"type": "integer"
},
"finish_reason": {
"type": "string"
},
"logprobs": {}
},
"required": [
"text",
"index",
"finish_reason",
"logprobs"
]
}
},
"usage": {
"type": "object",
"properties": {
"completion_tokens": {
"type": "integer"
},
"prompt_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
}
}
}
}
view raw schema.txt hosted with ❤ by GitHub

Add an “Initialize variable” action.

Add a “Set variable” action, and choose “text” as the value. It now will automaticaly put this inside an “Apply to each” loop.

Create three parallel Conditions with a Move email action under “if Yes”.

Now all you have to do is to save the flow and start sending emails.

Here are some examples that I sent and got sorted into the correct folder.

Hope this gives you some inspiration on what you can do with Azure OpenAI text genearation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s