Power Platform – ChatGPT Custom Connector
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”
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
3. Definition
This step is very important, in which you will define your request and response bodies.
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.
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”
At this stage, we will define the default values of our request, in preparation of the tests.
Ready to test ? First you will need to create a new connection.
When you click “New Connection“, you will be prompted to enter your OpenAi API Key.
Get your OpenAI Api Key
- Navigate to https://platform.openai.com/account/api-keys
- When you signup or log in, you will see the list of API Keys,
- Click “+ Create new secret key“, and copy the API Key (safely) as we will need to reuse it multiple times.
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.
Next, within the operations section, you should see your new Operation “ChatGPT Query“, switch to Raw Body, and paste the following body structure
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
Copy the response’s body, and go back to the Definition step.
Scroll down to “Response”, and click “Add default response”.
Paste the body’s content previously copied.
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 😉