Get, validate and save customer data to Dataverse using Azure OpenAI

Get, validate and save customer data to Dataverse using Azure OpenAI

In today's fast-paced business world, customer data is an invaluable asset that can help companies make informed decisions and stay ahead of the competition. However, the process of collecting and analyzing customer information can be time-consuming and tedious, especially for large businesses with thousands of customers. This is where the power of artificial intelligence (#AI) comes in. By using AI tools like #Azure #OpenAI, companies can streamline the process of gathering customer information, saving time and resources while also gaining valuable insights into customer behavior and preferences.

?

In this article, I will show how Azure OpenAI can be used to improve customer data collection and analysis, and the benefits it can bring to businesses of all sizes. We will build a Power Automate flow that triggered when a new account record is created in the Dataverse table. This flow will take the account name and send it to Azure OpenAI for collecting information about the company (number of employees, industry and 3 news). Received information will be saved in the Dataverse table.


Even more, if you want to start with pre-configured solution - look at the end of this article, I prepare something exactly for you ??

?

Prerequisites

?

Step 1. Create Azure OpenAI resource

To be able to create an Azure OpenAI resource you need to request the access in advance (at least now). You can apply for access to Azure OpenAI by completing the form at https://aka.ms/oai/access.

Once you receive the access follow below steps to create a resource for your solution.

1. In the browser open the page to create Azure OpenAI service and login with your credentials

2. On the Basics page provide information described below and click Next button

  • Subscription: Select the Azure subscription used in your OpenAI onboarding application
  • Resource group: The Azure resource group that will contain your OpenAI resource. You can create a new group or add it to a pre-existing group.
  • Region: The location of your instance. Different locations may introduce latency, but have no impact on the runtime availability of your resource.
  • Name: A descriptive name for your cognitive services resource. For example, MyOpenAIResource.
  • Pricing Tier: Only 1 pricing tier is available for the service currently

No alt text provided for this image

3. On the Tags screen click the Next button

4. On the Review + submit screen click the Create button

?

Step 2. Deploy a model

1. Open the Azure OpenAI resource created in the previous step

2. Go to the Model deployments tab and click the Create button

3. Provide information about the model you would like to create (for this sample select the text-davinci-003 model) and click the Save button

No alt text provided for this image

Please note that each model can be deployed only once in the Azure OpenAI service. On the screenshot above I selected the text-davinci-002 model because the text-davinci-003 model already deployed in my resource and disabled for the selection.

No alt text provided for this image


Step 3. Save parameters for later

In our flow we will use HTTP action to send request to the Azure OpenAI service. For this action we need following information from the Azure OpenAI service:

  • Endpoint
  • Secret Key
  • URI
  • Body for request

Let's collect this data.

1. Go to the Overview tab of your Azure OpenAI service and copy Endpoint value

No alt text provided for this image

2. Go to the Keys and Endpoint tab and copy KEY 1 value

No alt text provided for this image

3. To get the rest of information we need to go to Azure OpenAI Studio. Go to the Model deployment tab and click on the Go to Azure OpenAI Studio button

No alt text provided for this image

In the opened window click the Completions playground button.

In the Playground click the View code button.

In the pop-up window switch to the json format, copy Base URL and body

No alt text provided for this image

?

Step 4. Test API request in Postman

Before creating a flow I recommend to test your request in the Postman to be sure that everything is working as expected.

1. Open Postman and create a new request

2. Change method to POST and past the URI that you copied from the Playground

3. Add Headers:

Content-type: application/jso

api-key: <YOUR_KEY_FROM_AZURE_OPENAI>n        
No alt text provided for this image

4. On the Body tab switch to raw and add body that you copied from the Playground

Don't forget to add your request in the prompt

No alt text provided for this image

Once you are ready - click the Send button. The request should be sent successfully and you should receive response with the status code 200.

No alt text provided for this image

?

Step 5. Prepare your Power Automate flow

?Now, when all the puzzle pieces are in place, let's put them together and create our awesome flow!

1. Go to https://make.powerautomate.com/, open your environment with Dataverse where you are going to create a flow, open the Create tab and click on the Automated cloud flow button

No alt text provided for this image

2. Enter your flow name, find the Dataverse trigger When a row is added, modified or deleted and click the Create button

No alt text provided for this image

3. Configure the trigger as shown on the screenshot below and click New step button

No alt text provided for this image

4. In this flow with the help of Azure OpenAI we are going to get information about number of employees, industry and 3 news about the customer. Let's initialize 3 variables to store this information.

In the search field type "initialize" and select the action Initialize variable

No alt text provided for this image

Type the variable name, change the Type to String. Repeat two times to create all 3 variables.

No alt text provided for this image

Additionally initialize a variable to store a part with required data from the response received from Azure OpenAI. In my example I'll create varResponse variable for this purpose.

Once ready - click Next button

5. The next action will be HTTP which will send our request to Azure OpenAI. Let's configure it.

  • Method: POST
  • URI: copy URI from the Postman. The value should be copied before the question mark.
  • Headers:

Content-type: application/json

api-key: <YOUR_KEY_FROM_AZURE_OPENAI>

  • Queries:

api-version: 2022-12-01

  • Body: Copy from the Postman. Change the max_token value to 500 and replace prompt with the request that guide Open AI what you would like to find.

Sample prompt:

Find information about the company <YOUR_DYNAMIC_CONTENT> and provide the information using following sample: 1) number of employees: (provide just the whole number); 2) industry: (provide just the industry name); 3) 3 latest news about the company: (provide just a list)        

Don't forget to replace <YOUR_DYNAMIC_CONTENT> with the field Account Name from the Dynamic content.

No alt text provided for this image

6. Now we need to extract information from the Azure OpenAI response.

As you remember when we tested API request in Postman we received response in JSON schema which included metadata and information that we needed.

Take a look at the response:

{
????"id":?"cmpl-76NyozqSz3ZvYmGVmOimDD50KdVeu",
????"object":?"text_completion",
????"created":?1681756502,
????"model":?"text-davinci-003",
????"choices":?[
????????{
????????????"text":?"\n\nIBM?is?a?technology?and?consulting?company,?specializing?in?providing?enterprise?solutions,?including?cloud?computing,?artificial?intelligence,?analytics,?and?blockchain?technology.",
????????????"index":?0,
????????????"finish_reason":?"stop",
????????????"logprobs":?null
????????}
????],
????"usage":?{
????????"completion_tokens":?30,
????????"prompt_tokens":?7,
????????"total_tokens":?37
????}
}        

The information we are interested in is located in the choice array.

Let's add the new step in our flow - Set variable. For the Name field select a variable that you initialized earlier for storing response. For the Value filed write the following expression:

body('HTTP')['choices'][0]['text']        
No alt text provided for this image

7. Now let's save and test this part of our flow before we proceed with the next extraction and validation steps. Click on the Save button and go back to the flow card.

Add a new record to the Account table to trigger the flow.

?Check that all steps was completed without errors.

No alt text provided for this image

Explorer the structure of the response received from Azure OpenAi and stored in the variable.

No alt text provided for this image

Note that first two rows are always returns as blank. It is important for the future validation and cleaning steps.

8. Go back to the Edit mode of your flow. Let's add some more steps to split data into variables.

Add step Set variable, select your variable for employees, enter following expression for the Value:

slice(

  split(

    variables('varResponse'),

    decodeUriComponent('%0A')

  )[2],

  3,

  indexOf(

    split(

      variables('varResponse'),

      decodeUriComponent('%0A')

    )[2],

    ';'

  )

)        

Add another step Set variable, select your variable for industry, enter following expression for the Value:

slice(

  split(

    variables('varResponse'),

    decodeUriComponent('%0A')

  )[2],

  add(

    indexOf(

      split(

        variables('varResponse'),

        decodeUriComponent('%0A')

      )[2],

      ';'

    ),

    5

  ),

  lastIndexOf(

    split(

      variables('varResponse'),

      decodeUriComponent('%0A')

    )[2],

    ';'

  )

)        

Add one more step Set variable, select your variable for news, enter following expression for the Value:

concat(

  split(

    variables('varResponse'),

    decodeUriComponent('%0A')

  )

  [sub(

    max(

      length(

        split(

          variables('varResponse'),

          decodeUriComponent('%0A')

        )

      )

    ),

    3

  )

  ],

  decodeUriComponent('%0A'),

  split(

    variables('varResponse'),

    decodeUriComponent('%0A')

  )

  [sub(

    max(

      length(

        split(

          variables('varResponse'),

          decodeUriComponent('%0A')

        )

      )

    ),

    2

  )

  ],

  decodeUriComponent('%0A'),

  split(

    variables('varResponse'),

    decodeUriComponent('%0A')

  )

  [sub(

    max(

      length(

        split(

          variables('varResponse'),

          decodeUriComponent('%0A')

        )

      )

    ),

  1

)

]

)        

?9. And the last step of our flow is for storing to Dataverse information that we extracted. Add a new step Update a row.

Select Account table, add Row ID from the dynamic content.

Add variables' value to a row. For this sample I'm going to store all information in one field Description. But you can decide to create special fields for this purpose.

No alt text provided for this image


Step 6. Test your flow

Save your flow and test it. Create a new record in the Account table and check that everything working as expected.

No alt text provided for this image

?

Keep in mind

We explored a sample of the flow that helps collecting information about a company.

Keep in mind that Azure OpenAI models (versions that available today) are using trained data up to 2019-2021 years (more information here: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/concepts/models#gpt-3-models-1).

You can adjust this flow according your requirements, as well as fine tune a model (more information here: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/fine-tuning?pivots=programming-language-studio).

Before deploy in production test your flow multiple times and explore the possible variants of the response structure. You might want to add additional validations in the flow for flexible processing received data.

?

??Want a quick start?

Then you can explore ready to use connector and flow that I created and published on GitHub:

?

You can follow step-by-step instruction in ReadMe files to prepare resources, download and install solutions.

?

Conclusion

In conclusion, the use of OpenAI for customer data collection and analysis is a game-changer for businesses looking to stay ahead of the curve. By automating the process of gathering and analyzing customer information, companies can save time and resources while gaining valuable insights into customer behavior and preferences. OpenAI's advanced algorithms can help businesses identify patterns and trends in customer data that would be difficult, if not impossible, for humans to detect. As AI technology continues to advance, it is becoming an increasingly essential tool for businesses looking to stay competitive in today's market. By embracing AI-powered solutions like OpenAI, companies can unlock the full potential of their customer data and gain a significant advantage over their competitors.

?

#PowerPlatform #PowerAutomate #Dataverse #SharingIsCaring

要查看或添加评论,请登录

Katerina Chernevskaya的更多文章

社区洞察

其他会员也浏览了