Call OpenAI API using PowerApps and Power Automate

Spread the learning

In this blog post, I will demonstrate how to consume OpenAI API from PowerApps via PowerAutomate. It will be kind of ChatGPT3 experience where user can put forward any question in PowerApps, OpenAI will answer that.

Before we begin this, I would highly recommend to go through my first blog on OpenAI account setup and how to create API Key.

Here is the URL – https://kloudscoop.com/getting-started-with-openai-api-and-postman/

1. Create New Flow in PowerAutomate
  • Go to the PowerAutomate
  • Create new ‘Instant cloud flow’ 
  •  Initialize the variable, this would be the question which will get passed from PowerApps.
  •  Next insert HTTP action, which will call to OpenAI end point. In Header section put Authorization – Bearer Token and in Body section pass on the JSON as shown below. Please note here prompt would be the dynamic question variable initialized above.
  • Finally return respose to PowerApps, this is the response or answer which we will get from OpenAI API.
  • You need to parse JSON and the experssion would be outputs(‘Q&AAPI’)?[‘body’]?[‘choices’][0]?[‘text’]
  • Save the Flow
 
2. Create New PowerApps
  • Go to the PowerApps and create new App
  • Note: We will not go in detail/step by step process to create PowerApps we will stick to the purpose of this Post.
  • Add 3 lables (Question, Answer and one lable to populate answer from OpenAI ), textbox (ask the question) and button
  • On click of button i.e. on OnSelect property call your PowerAutomate Flow as shown below and in parameter pass question from textbox
  • Save the PowerApps. You are done.
  • Now let’s the magic begin!!
  • See this video, where OpenAI is answering our questions on Classification, Translation, General questions