top of page
Writer's pictureAlan Campbell

ChatGPT Power Platform Connector Odyssey - Part 1

Updated: Oct 30, 2023

Welcome back, dear readers! If you joined us for the inaugural entry of this series, you'll recall the exhilarating commencement of our journey, weaving together the transformative capabilities of ChatGPT with the adaptability of Power Platform. As we move forward, our endeavor to harness the best of both worlds is only gaining momentum.


Laying the Foundation with the Custom Connector: To recap, our foremost endeavor is to chisel out a Power Platform Custom Connector. A monumental task, yes, but one we are undertaking with precision and care. This is our keystone, a meticulously crafted conduit meant to assure that our dialogues with ChatGPT aren’t just superficial pings, but deep, fluent conversations. This connector is the linchpin, acting as our steadfast bridge to a world where human-AI interactions are not a thing of the future, but a present reality.


In today's installment, we're delving deeper, shedding light on the nuances, intricacies, and perhaps the occasional stumbling blocks we might encounter. Whether you're here for the technical know-how or simply to witness the magic of two technological titans coming together, there's plenty in store. So, grab a cup of your favorite brew, settle in, and let's embark on the second chapter of this riveting tech saga!


1. First, you need to have a ChatGPT account and fund your API access. Please note that just having a ChatGPT account is not enough. The API access is over and above just having an ChatGPT account.


2. In PowerApps, click on the ... More button in the left navigation pane followed by the Discover All button.

Click on the Discover all button in Power Apps
Click on the Discover all button in Power Apps

3. Look for the Data section and then pin the Custom connections option to the navigation pane on the left as you will be referencing the option often.

Pin the Custom connectors to the Navigation Pane in Power Apps
Pin the Custom connectors to the Navigation Pane in Power Apps

4. Click on Custom connectors in the left navigation pane and then click on New custom connector in the upper right corner and select the Create from blank option. Provide a name for the connector. I called mine ChatGPT.

Click on New custom connector in Power Apps
Click on New custom connector in Power Apps

5. General Tab. Enter the following under the General tab.


a. Enter api.openai.com under the host setting.

Enter the api.openai.com Host Name in the Custom Connector
Enter the api.openai.com Host Name in the Custom Connector

6. Security Tab. Enter the following under the Security tab.


a. Select the API key under the authentication type.

b. Under the Parameter label enter: API Key.

c. Under the Parameter name enter: Authorization.

Enter the Authentication Type in Power Apps
Enter the Authentication Type in Power Apps

7. Definition Tab. Click on New action in the left action pane.

Create a New Action in Definitions Section of Power Apps
Create a New Action in Definitions Section of Power Apps

General Section. Enter the following on the General section.


a. Under Summary enter: History Analysis.

b. Under Description enter: This will analyze Business Central history

c. Under Operation ID enter: HistoryAnalysis.

Add the Operation ID to the General Tab of the Custom Connector
Add the Operation ID to the General Tab of the Custom Connector

Request Section. Under the Request section click on the Import from sample button.


a. Select Post under the Verb section.

b. Under the Headers enter: Content-Type: application/json

c. Under the Body paste the code below.

d. Then click Import.


{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ]
  }

Content -type. Edit the Content Type under the Headers in the Request section.


a. Under Default Type enter: application/json

b. Set the Is required? to true.

b. Change Visibility to Internal.

c. Click the back button.

Add the Content Type Parameter to the Custom Connector
Add the Content Type Parameter to the Custom Connector

body. Edit the body under Body in the Request section.


a. Set the Is required? to true.


Content. Edit the content parameter.


a. Set the Title to Analyst Request.

b. Set the Is required? to true.

c. Set the Visibility to Important.

d. Click the Back button.

Update the Content Parameter Settings in the Custom Connector
Update the Content Parameter Settings in the Custom Connector

Role. Edit the Role Parameter


a. Set the Title to: Role.

b. Set the Default value to: user.

c. Set the Is required? to true.

d. Set the Visibility to Important.

e. Click the Back button.

Update the Role Parameter in the Custom Connector
Update the Role Parameter in the Custom Connector

Model. Edit the Model Parameter.


a. Set the Title to: Model.

b. Set the Default value to: gpt-4.

c. Set the Is required? to true.

d. Set the Visibility to Important.

e. Click the Back button.

Update the Model Parameter in the Custom Connector
Update the Model Parameter in the Custom Connector

8. Click the Create connection button in the menu.

Click Create Connector in Power Apps
Click Create Connector in Power Apps

Test and Complete the Response Section for the Connector


9. You will need an API key from ChatGPT to test the connector.


10. Click on Test in the menu and then on New connection. Enter in the API Key field the word Bearer, then a space followed by your API Key.



Enter Bearer and then the API Key in the Custom Connector to ChatGPT
Enter Bearer and then the API Key in the Custom Connector to ChatGPT

11. Click Edit on the ChatGPT connector in the Custom connector list in the left navigation pane. Then, click on Test in the menu. You now see a date and time stamp in the Connections box. Enter a question for ChatGPT in the content field and click Test operation. You should see a 200 status in the results.

Test the ChatGPT Custom Connector in Power Apps
Test the ChatGPT Custom Connector in Power Apps

12. Copy the results from the Body section under the response tab. My response was the following:


{
  "id": "chatcmpl-7sdKOJDlMmdxYflm8jPtbL9bHK3jR",
  "object": "chat.completion",
  "created": 1693255244,
  "model": "gpt-4-0613",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "There are 8 planets in this solar system."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 17,
    "completion_tokens": 10,
    "total_tokens": 27
  }
}

13. Definitions Tab. Click on the Definitions tab in the menu and then enter the following.


a. Under the Response section click on the Default button.

b. Click on the Import from sample button.

c. Enter in the headers Content-Type application/json

d. Paste your results from the Body section in the previous step into the Body Field.

e. Click the Import button.

Import the API Response in the Custom Connector for ChatGPT
Import the API Response in the Custom Connector for ChatGPT

14. Click on Update connector in the menu. The connector is now ready!


Conclusion: One Giant Leap Towards Seamlessly Integrated Conversations

And there it is! If you've been following along, you’ve just completed an essential component in a much larger puzzle. We've successfully built a Power Platform Custom Connector that serves as a dynamic bridge to ChatGPT, allowing us to initiate complex, human-like interactions through AI.

While the monumental task of crafting a custom connector may have seemed daunting at first, breaking it down into bite-sized, actionable pieces made it achievable. Starting with the necessary preparations for API access on ChatGPT, we've walked through each parameter and tab that needed to be configured in the Power Platform. We even ran tests to ensure everything is set up for fluent dialogues, thereby confirming the reliability and efficiency of our new connector.

Now, what lies ahead?

  • Refinement: We've laid the groundwork, but that's just the beginning. Upcoming blogs will delve into fine-tuning and enhancing our custom connector.

  • Integration with Business Central: While our focus today was exclusively on linking Power Platform to ChatGPT, stay tuned for the next exciting phase where we'll introduce interactions with Business Central.

  • Exploring Use Cases: The real value of this integration will become apparent as we start implementing it in real-world scenarios.

Your journey towards unlocking the full potential of ChatGPT within your Power Platform applications has just started. Each step from here will only add another layer of capabilities and functionalities, expanding what's possible for your business or project.

We hope this chapter has been both instructional and inspiring. Building this connector sets the stage for some truly innovative solutions, and we can't wait to take you along for the rest of this ride.

Until our next exciting installment, happy building!




60 views0 comments

Comments


bottom of page