SamTech 365

Power Platform, Copilot & SharePoint guides by Samir Daoudi

Power Platform – ChatGPT Custom Connector

Create a Power Platform custom connector for the OpenAI ChatGPT API so you can call it from Power Apps and Power Automate. Step by step.
ChatGPT

In Today’s article, I will take you through the steps to create a custom PowerPlatform connector to communicate with Chat GPT.

Create the custom connector

1. General

Navigate to PowerAutomate, locate the Data > Custom Connectors and click “New”
Power Platform - ChatGPT Custom Connector
You will be taken through a wizard. The first step is to set your connector name, image and background colors.
Make sure to set the Scheme to HTTPS and the host to “api.openai.com”

2. Security

The next consists in defining the way you authenticate with the ChatGPT API.

Authentication Method: API Key
Parameter label : [Anything], in this example API KEY
Parameter Name: Authorization
Parameter Location: Header

Power Platform - ChatGPT Custom Connector – screenshot 2

3. Definition

This step is very important, in which you will define your request and response bodies.

Power Platform - ChatGPT Custom Connector – screenshot 3

The first thing you will need to define is the General section, in which you can provide a name and description of your query. These can be anything.

In my example, I canned the action “Query” and for the description, I just used “Ask Chat GPT anything“.

More importantly, you will need to pick which operation ID you will use from the API, please make sure to use the operation “ChatGPT Query“.

Next, you will need to import the request schema from a sample.

Power Platform - ChatGPT Custom Connector – screenshot 4

Click the “Import from sample” button and populate the following fields:

  • Verb: Post
  • Url: https://api.openai.com/v1/completions
  • Headers:
Content-Type application/json
  • Body:
Request Body:
{
"model": "text-davinci-003",
"prompt": "What's a custom connector",
"max_tokens": 1000,
"temperature": 0,
"n": 1
}

At this stage, you are ready to create the connector, from the wizard on top, click “Create connector”

Power Platform - ChatGPT Custom Connector – screenshot 5

At this stage, we will define the default values of our request, in preparation of the tests.

Power Platform - ChatGPT Custom Connector – screenshot 6

 

Ready to test ? First you will need to create a new connection.

Power Platform - ChatGPT Custom Connector – screenshot 7

When you click “New Connection“, you will be prompted to enter your OpenAi API Key.

Power Platform - ChatGPT Custom Connector – screenshot 8

Get your OpenAI Api Key

  1. Navigate to https://platform.openai.com/account/api-keys
  2. When you signup or log in, you will see the list of API Keys,

Power Platform - ChatGPT Custom Connector – screenshot 9

  1. Click “+ Create new secret key“, and copy the API Key (safely) as we will need to reuse it multiple times.

Power Platform - ChatGPT Custom Connector – screenshot 10

Back to PowerPlatform connection, paste the new key in the connection prompt and save it.

You might need to refresh the list of connections to load the newly created connection.

Power Platform - ChatGPT Custom Connector – screenshot 11

 

Next, within the operations section, you should see your new Operation “ChatGPT Query“, switch to Raw Body, and paste the following body structure

Power Platform - ChatGPT Custom Connector – screenshot 12

Request Body:
{
"model": "text-davinci-003",
"prompt": "What's a custom connector",
"max_tokens": 1000,
"temperature": 0,
"n": 1
}

Click “Test operation“, and after couple of seconds, you should see the following response

Power Platform - ChatGPT Custom Connector – screenshot 13

 

Copy the response’s body, and go back to the Definition step.

Scroll down to “Response”, and click “Add default response”.

Power Platform - ChatGPT Custom Connector – screenshot 14

Paste the body’s content previously copied.

Power Platform - ChatGPT Custom Connector – screenshot 15

 

Et voila ! That’s your connector created, you can re-test it if you want.

In next article, I will show you how we can use this connector in PowerApps and/or Power Automate.

 

Enjoy 😉

Related guides

Discover more from SamTech 365

Subscribe now to keep reading and get access to the full archive.

Continue reading