Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Sample: Get, validate and save customer data to Dataverse using Azure OpenAI #47

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
132 changes: 132 additions & 0 deletions samples/Get-required-info-with-AzureOpenAI_CustomConnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Get required info with Azure OpenAI - custom connector

## Summary

This custom connector enables to create and send a POST request to the Azure OpenAI service to get required information. The output received from the Azure OpenAI service stored in JSON schema and can be used in different flows and apps.

![General information of the custom connector](./assets/CustomConnector_GeneralInformation.png)
![Definition configuration of the custom connector](./assets/CustomConnector_Definition.png)

## Applies to

* [Microsoft Power Automate](https://docs.microsoft.com/power-automate/)
* [Azure OpenAI](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/)

## Compatibility

> Don't worry about this section, we'll take care of it. Unless you really want to...

![Premium License](https://img.shields.io/badge/Premium%20License-Not%20Required-green.svg "Premium license not required")
![On-Premises Connectors](https://img.shields.io/badge/On--Premises%20Connectors-No-green.svg "Does not use on-premise connectors")
![Custom Connectors](https://img.shields.io/badge/Custom%20Connectors-Not%20Required-green.svg "Does not use custom connectors")

## Authors

Solution|Author(s)
--------|---------
Get-required-info-with-AzureOpenAI_CustomConnector | [Katerina Chernevskaya](https://github.com/Katerina-Chernevskaya) ([LinkedIn](https://www.linkedin.com/in/katerinachernevskaya/)), Awara IT Academy

## Version history

Version|Date|Comments
-------|----|--------
1.0|April 11, 2023|Initial release

## Features

This sample illustrates the following concepts:

* Using variables to store information about Azure OpenAI service parameters for easy and straightforward parameter management
* Creating POST request to Azure OpenAI service to get information
* API response configuration to use received data in the future actions (flows, apps, etc.)

## Prerequisites

* Azure subscription
* Azure OpenAI resource created
* A model deployed using Azure OpenAI
* Saved Azure OpenAI service and model parameters

Follow below steps to create an Azure OpenAI resource and deploy a model in advance.

### Create Azure OpenAI resource

*Currently, access to Azure OpenAI service is granted only by application. You can apply for access to Azure OpenAI by completing the form at [https://aka.ms/oai/access](https://aka.ms/oai/access).*

1. In the browser open the page to create [Azure OpenAI service](https://portal.azure.com/?microsoft_azure_marketplace_ItemHideKey=microsoft_openai_tip#create/Microsoft.CognitiveServicesOpenAI) and login with your credentials
2. On the `Basics` page provide information described bellow 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
![Create Azure OpenAI service](./assets/AzureOpenAI_Basics.png)
3. On the `Tags` screen click the `Next` button
4. On the `Review + submit` screen click the `Create` button

### 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 custom connector select the `text-davinci-003` model) and click the `Save` button

### Save parameters
To launch this custom connector you will need following information: host, base URL and API key. Save this information for later.
1. Go to the `Overview` tab of your Azure OpenAI service and copy `Endpoint` value
![Copy Endpoint value](./assets/AzureOpenAI_HostSave.png)
2. Go to the `Keys and Endpoint` tab and copy `KEY 1` value
![Copy api-key value](./assets/AzureOpenAI_ApiKeySave.png)
3. Go to the `Model deployments` tab, select your model and click on the `Go to Azure OpenAI Studio` button
![Go to Azure OpenAI Studio](./assets/AzureOpenAI_OpenStudio.png)
In the opened window click the `Completions playground` button
![Completions playground](./assets/AzureOpenAI_Playground.png)
In the Playground click the `View code` button
![View Code](./assets/AzureOpenAI_ViewCode.png)
In the pop-up window switch to the `json` format and copy Base URL (marked in yellow on the screenshot below)
![Save Base URL](./assets/AzureOpenAI_BaseUrlSave.png)

## Minimal Path to Awesome

* Download the `.zip` from the `solution` folder
* Go to [Power Automate Studio](https://make.powerautomate.com/), go to `Solutions` and click `Import solution`
![Import solution - step 1](./assets/Import_Step1.png)
* Select the solution by clicking `Brows` button and press the `Next` button
* Review all fields on the next screen and click `Next` button
![Import solution - step 2](./assets/Import_Step2.png)
* On the next screen provide information that you stored as prerequsines:
For the `BaseURL` field use the value that you copied from the Playground.
For the `Host` field use the value that you copied from the `Endpoint` field.
Once you are ready - click `Import` button.
![Import solution - step 3](./assets/Import_Step3.png)

*After the solution will be imported successfully - you will see the notification and the solution will be available in the list.*
![Import solution - done](./assets/Import_Done.png)

* Open the solution `AzureOpenAI_CustomConnector` and update Environmental Variables value.
![Update Environment Variable](./assets/UpdateVariable.png)

*Once all steps will be completed you can use this custom connector to create connections and leverage its capabilities in your solutions.*

## Disclaimer

**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**

## Help

> Note: don't worry about this section, we'll update the links.

We do not support samples, but we this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.

If you encounter any issues while using this sample, [create a new issue](https://github.com/pnp/powerautomate-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=bug-report.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

For questions regarding this sample, [create a new question](https://github.com/pnp/powerautomate-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=question.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/powerautomate-samples/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected&template=suggestion.yml&sample=YOURSAMPLENAME&authors=@YOURGITHUBUSERNAME&title=YOURSAMPLENAME%20-%20).

## For more information

- [Create your first flow](https://docs.microsoft.com/en-us/power-automate/getting-started#create-your-first-flow)
- [Microsoft Power Automate documentation](https://docs.microsoft.com/en-us/power-automate/)


<img src="https://telemetry.sharepointpnp.com/powerautomate-samples/samples/readme-template" />

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"api_key":{"type":"securestring","uiDefinition":{"displayName":"API key","description":"The API key for this api","tooltip":"Provide your API key","constraints":{"tabIndex":2,"clearText":false,"required":"true"}}}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"Default title","description":"","version":"1.0"},"host":"@environmentVariables(\"kch_Host\")","basePath":"/@environmentVariables(\"kch_BaseURL\")","schemes":["https"],"consumes":[],"produces":[],"paths":{"/":{"post":{"responses":{"default":{"description":"default","schema":{"type":"object","properties":{"id":{"type":"string","description":"id"},"object":{"type":"string","description":"object"},"created":{"type":"integer","format":"int32","description":"created"},"model":{"type":"string","description":"model"},"choices":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string","description":"text"},"index":{"type":"integer","format":"int32","description":"index"},"finish_reason":{"type":"string","description":"finish_reason"},"logprobs":{"type":"string","description":"logprobs"}}},"description":"choices"},"usage":{"type":"object","properties":{"completion_tokens":{"type":"integer","format":"int32","description":"completion_tokens"},"prompt_tokens":{"type":"integer","format":"int32","description":"prompt_tokens"},"total_tokens":{"type":"integer","format":"int32","description":"total_tokens"}},"description":"usage"}}}}},"summary":"POST request parameters","operationId":"GeneralParameters","parameters":[{"name":"api-version","in":"query","required":false,"type":"string"},{"name":"Content-Type","in":"header","required":false,"type":"string"},{"name":"api-key","in":"header","required":false,"type":"string"},{"name":"body","in":"body","required":false,"schema":{"type":"object","properties":{"prompt":{"type":"string","description":"prompt"},"max_tokens":{"type":"integer","format":"int32","description":"max_tokens"},"temperature":{"type":"integer","format":"int32","description":"temperature"},"frequency_penalty":{"type":"integer","format":"int32","description":"frequency_penalty"},"presence_penalty":{"type":"integer","format":"int32","description":"presence_penalty"},"top_p":{"type":"number","format":"float","description":"top_p"},"best_of":{"type":"integer","format":"int32","description":"best_of"},"stop":{"type":"string","description":"stop"}}}}]}}},"definitions":{},"parameters":{},"responses":{},"securityDefinitions":{"api_key":{"type":"apiKey","in":"header","name":"api-key"}},"security":[],"tags":[]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="xml" ContentType="application/octet-stream" /><Default Extension="json" ContentType="application/octet-stream" /><Default Extension="Png" ContentType="application/octet-stream" /></Types>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ImportExportXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Entities></Entities>
<Roles></Roles>
<Workflows></Workflows>
<FieldSecurityProfiles></FieldSecurityProfiles>
<Templates />
<EntityMaps />
<EntityRelationships />
<OrganizationSettings />
<optionsets />
<CustomControls />
<EntityDataProviders />
<Connectors>
<Connector>
<connectorid>a5b380c8-5874-4bf2-8f78-c579bd454f1e</connectorid>
<description></description>
<displayname>Azure Open AI for CRM</displayname>
<iconbrandcolor>#007ee5</iconbrandcolor>
<name>kch_5Fazure-20open-20ai-20for-20crm</name>
<connectortype>1</connectortype>
<openapidefinition>/Connector/kch_5Fazure-20open-20ai-20for-20crm_openapidefinition.json</openapidefinition>
<connectionparameters>/Connector/kch_5Fazure-20open-20ai-20for-20crm_connectionparameters.json</connectionparameters>
<policytemplateinstances>/Connector/kch_5Fazure-20open-20ai-20for-20crm_policytemplateinstances.json</policytemplateinstances>
<iconblob>/Connector/kch_5Fazure-20open-20ai-20for-20crm_iconblob.Png</iconblob>
</Connector>
</Connectors>
<Languages>
<Language>1033</Language>
</Languages>
</ImportExportXml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<environmentvariabledefinition schemaname="kch_BaseURL">
<description default="Put your Azure Open AI base UL. Sample: /openai/deployments/YOURMODELNAME/completions">
<label description="Put your Azure Open AI base UL. Sample: /openai/deployments/YOURMODELNAME/completions" languagecode="1033" />
</description>
<displayname default="BaseURL">
<label description="BaseURL" languagecode="1033" />
</displayname>
<introducedversion>1.0.0.0</introducedversion>
<iscustomizable>1</iscustomizable>
<isrequired>0</isrequired>
<secretstore>0</secretstore>
<type>100000000</type>
</environmentvariabledefinition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<environmentvariabledefinition schemaname="kch_Host">
<description default="Put Azure Open AI host name. Sample: YOURNAME.openai.azure.com">
<label description="Put Azure Open AI host name. Sample: YOURNAME.openai.azure.com" languagecode="1033" />
</description>
<displayname default="Host">
<label description="Host" languagecode="1033" />
</displayname>
<introducedversion>1.0.0.0</introducedversion>
<iscustomizable>1</iscustomizable>
<isrequired>0</isrequired>
<secretstore>0</secretstore>
<type>100000000</type>
</environmentvariabledefinition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<ImportExportXml version="9.2.23032.184" SolutionPackageVersion="9.2" languagecode="1033" generatedBy="CrmLive" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SolutionManifest>
<UniqueName>AzureOpenAI_CustomConnector</UniqueName>
<LocalizedNames>
<LocalizedName description="AzureOpenAI_CustomConnector" languagecode="1033" />
</LocalizedNames>
<Descriptions />
<Version>1.0.0.1</Version>
<Managed>0</Managed>
<Publisher>
<UniqueName>KaterinaChernevskaya</UniqueName>
<LocalizedNames>
<LocalizedName description="Katerina Chernevskaya" languagecode="1033" />
</LocalizedNames>
<Descriptions>
<Description description="Solution created by Katerina Chernevskaya. Follow me https://www.linkedin.com/in/katerinachernevskaya/" languagecode="1033" />
</Descriptions>
<EMailAddress>[email protected]</EMailAddress>
<SupportingWebsiteUrl>https://www.linkedin.com/in/katerinachernevskaya/</SupportingWebsiteUrl>
<CustomizationPrefix>kch</CustomizationPrefix>
<CustomizationOptionValuePrefix>84224</CustomizationOptionValuePrefix>
<Addresses>
<Address>
<AddressNumber>1</AddressNumber>
<AddressTypeCode>1</AddressTypeCode>
<City xsi:nil="true"></City>
<County xsi:nil="true"></County>
<Country>Bulgaria</Country>
<Fax xsi:nil="true"></Fax>
<FreightTermsCode xsi:nil="true"></FreightTermsCode>
<ImportSequenceNumber xsi:nil="true"></ImportSequenceNumber>
<Latitude xsi:nil="true"></Latitude>
<Line1 xsi:nil="true"></Line1>
<Line2 xsi:nil="true"></Line2>
<Line3 xsi:nil="true"></Line3>
<Longitude xsi:nil="true"></Longitude>
<Name xsi:nil="true"></Name>
<PostalCode xsi:nil="true"></PostalCode>
<PostOfficeBox xsi:nil="true"></PostOfficeBox>
<PrimaryContactName xsi:nil="true"></PrimaryContactName>
<ShippingMethodCode>1</ShippingMethodCode>
<StateOrProvince xsi:nil="true"></StateOrProvince>
<Telephone1 xsi:nil="true"></Telephone1>
<Telephone2 xsi:nil="true"></Telephone2>
<Telephone3 xsi:nil="true"></Telephone3>
<TimeZoneRuleVersionNumber xsi:nil="true"></TimeZoneRuleVersionNumber>
<UPSZone xsi:nil="true"></UPSZone>
<UTCOffset xsi:nil="true"></UTCOffset>
<UTCConversionTimeZoneCode xsi:nil="true"></UTCConversionTimeZoneCode>
</Address>
<Address>
<AddressNumber>2</AddressNumber>
<AddressTypeCode>1</AddressTypeCode>
<City xsi:nil="true"></City>
<County xsi:nil="true"></County>
<Country xsi:nil="true"></Country>
<Fax xsi:nil="true"></Fax>
<FreightTermsCode xsi:nil="true"></FreightTermsCode>
<ImportSequenceNumber xsi:nil="true"></ImportSequenceNumber>
<Latitude xsi:nil="true"></Latitude>
<Line1 xsi:nil="true"></Line1>
<Line2 xsi:nil="true"></Line2>
<Line3 xsi:nil="true"></Line3>
<Longitude xsi:nil="true"></Longitude>
<Name xsi:nil="true"></Name>
<PostalCode xsi:nil="true"></PostalCode>
<PostOfficeBox xsi:nil="true"></PostOfficeBox>
<PrimaryContactName xsi:nil="true"></PrimaryContactName>
<ShippingMethodCode>1</ShippingMethodCode>
<StateOrProvince xsi:nil="true"></StateOrProvince>
<Telephone1 xsi:nil="true"></Telephone1>
<Telephone2 xsi:nil="true"></Telephone2>
<Telephone3 xsi:nil="true"></Telephone3>
<TimeZoneRuleVersionNumber xsi:nil="true"></TimeZoneRuleVersionNumber>
<UPSZone xsi:nil="true"></UPSZone>
<UTCOffset xsi:nil="true"></UTCOffset>
<UTCConversionTimeZoneCode xsi:nil="true"></UTCConversionTimeZoneCode>
</Address>
</Addresses>
</Publisher>
<RootComponents>
<RootComponent type="372" id="{a5b380c8-5874-4bf2-8f78-c579bd454f1e}" schemaName="kch_5Fazure-20open-20ai-20for-20crm" behavior="0" />
</RootComponents>
<MissingDependencies />
</SolutionManifest>
</ImportExportXml>
Loading