Unlocking the Power of Artificial Intelligence: Integrating Open AI with Power Apps
Create canvas app to enable Open AI Conversation
#OpenAI #CanvasApp #PowerPlatform #PowerAutomate
Open AI
Introduction — OpenAI API
As per Open AI Documentation
The Open AI API can be applied to virtually any task that involves understanding or generating natural language or code. We offer a spectrum of models with different levels of power suitable for different tasks, as well as the ability to fine-tune your own custom models. These models can be used for everything from content generation to semantic search and classification.
Playground :
In this playground we can validate model responses by configuring various parameters.
And also we can create integrate open AI API by creating API Keys under manage Account
Account==> View API Keys ==>Create
This article will not cover in depth about Open AI and will include help links to provide more context.
We will discuss about How to integrate Open AI in canvas Apps.
1.Create Power Automate Flow for Http Request
- Login to Power App portal & select respective environment
- Select Flows==>New Flow==>Instant Cloud Flow
- Enter Name of Flow and Under “Choose how to trigger this flow” Select PowerApps
- Select + Icon and Add Action && Search for Http under Triggers
1.1Configure Http Action:
Select Method as “POST”
URI : https://api.openai.com/v1/completions(This can change based on your interaction with API)
Under Headers section Please provide Key As “Authorization “ and Value as “Bearer <<API_KEY>>”
Under Body Section Please provide body object(which you can check from Open AI Playground).I am providing sample example here for your reference.
{
“prompt”: “@{triggerBody()[‘PowerApps_Input’]}”,//Input from Power App
“max_tokens”: 1000,
“temperature”: 0.9,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0.6,
“best_of”: 1,
“echo”: true,
“logprobs”: 0,
“model”: “text-davinci-001”
}
1.2 Parse JSON Action
After this step, Please select Parse JSON Action to parse response from API and then add action called “Respond to Power App or flow”
1.3 Respond to Power App or flow
Under “Respond to Power App or flow” please select type of output (in this case it is string )and value will be under choices in response
Ex: Key: OpenAiResponse , Value: body(‘Parse_JSON’)?[‘choices’][0][‘text’]
Click on Save & Close the flow section
2.Create Canvas App & Integrate Power Automate Workflow
Under Apps==>Click New App & Select Canvas App
2.1 Select TextInput control and add to the screen.
2.2 Search for “Search” Icon and add to the screen
2.3In Left Side Navigation ,Under “Power Automate” Please select existing instant cloud flow created in previous step.
2.4 On Search Icon Select Please add following formula
responseVariable;//Declare variable
Set(responseVariable,<<AutoMate_Flow_Name>>.Run(<<SearchText>>.Text).<<OutPut_Variable_Name>>);//in this case above output key : OpenAiResponse
2.5 Select HTML Control and drag to canvas screen & Set Default value to above variable “responseVariable”
After above changes clicks on “Save” && Run the application.
Help links
https://azure.microsoft.com/en-us/products/cognitive-services/openai-service
https://learn.microsoft.com/en-us/azure/cognitive-services/openai/overview