How to Create a Chat GPT Connector in Power Platform

AI is transforming the way we build solutions in Power Platform, and as someone who thrives on creating seamless, intelligent automation, I wanted to share a step-by-step guide on bringing ChatGPT into the mix. If you’ve ever wanted to add AI-driven conversations or automate complex decision-making within your apps, this one’s for you!

Integrating ChatGPT into Microsoft’s Power Platform can be approached in two primary ways:

  1. Using a Custom Connector:
    • Definition: A custom connector is a wrapper around a REST API that allows Power Platform applications to communicate with external services.
    • Implementation: By creating a custom connector for ChatGPT, you enable your Power Apps or Power Automate workflows to send prompts to and receive responses from ChatGPT directly within the platform. This involves defining the API endpoints, authentication methods, and request/response structures.
    • Use Case: Ideal for scenarios where you want to embed ChatGPT’s capabilities directly into your Power Platform solutions, allowing for seamless interactions without leaving the environment.
  2. Utilising the ChatGPT Web Service:
    • Definition: This approach involves interacting with ChatGPT through its standalone web interface or API, separate from the Power Platform environment.
    • Implementation: Users can access ChatGPT via its web portal for tasks like drafting content, generating ideas, or answering queries. While this method doesn’t involve direct integration, outputs from ChatGPT can be manually incorporated into Power Platform applications as needed.
    • Use Case: Suitable for situations where occasional use of ChatGPT’s capabilities is sufficient, and direct integration into Power Platform applications isn’t necessary.

Key Differences:

  • Integration Level: A custom connector provides seamless integration within the Power Platform, enabling automated workflows and real-time interactions. In contrast, using the ChatGPT web service requires manual intervention to transfer data between ChatGPT and Power Platform applications.
  • Automation and Efficiency: Integrating via a custom connector allows for automated processes, reducing the need for manual input and enhancing efficiency. Using the web service is more manual and may not be as efficient for repetitive tasks.
  • User Experience: A custom connector offers a more cohesive user experience within the Power Platform, while using the web service separately may disrupt workflow continuity.

In this blog, we’ll dive into the exciting process of creating a Chat GPT connector in Power Platform, and I’m saving the Web Services for the next blog!

Introduction to Power Platform Connectors

Power Platform connectors are a bridge between your apps and data sources, enabling seamless data flow and integration. By creating a custom connector, you can connect to virtually any service or API, including Chat GPT.

Prerequisites

Before you begin, ensure you have the following:

  • A Microsoft Power Platform account.
  • Access to the OpenAI GPT API (you will need an API key).
  • Basic understanding of APIs and JSON format.

Costs and Fees

The cost of using custom connectors in the Power Platform varies based on your Microsoft licensing and subscription model and may change over time. (It changes all the time, so please check the documentations!)

Power Apps and Power Automate Per User Plan: Custom connectors are included without extra charges within your allocated capacity. These plans offer a certain number of runs or actions per user per month.

Power Apps and Power Automate Per App or Per Flow Plan: Custom connector usage may incur additional costs if you exceed the limits on the number of runs or actions per app or flow.

Power Apps and Power Automate Premium Plans: These plans provide increased capacity and features, with costs varying based on the specific plan chosen.

For the most accurate and current information, refer to Microsoft’s official pricing and licensing documents.

The cost of using OpenAI’s API depends on the API endpoint, usage volume, and chosen plan.

GPT-3 API: Priced based on tokens processed (input and output). The price varies by usage level and plan.

Data and Model Costs: Additional fees may apply for certain data sources or fine-tuned models.

Pricing and offerings may change, so check OpenAI’s official website for the most current information.

Step-by-Step Guide to Creating a Chat GPT Connector

Step 1: Set Up Your OpenAI Account

To interact with the Chat GPT API, you need to set up an account with OpenAI and obtain your API key.

  • Visit the OpenAI website and create an account.
  • Navigate to the API section and generate a new API key.
  • Note down this key as you will need it later.

Step 2: Create a Custom Connector in Power Platform

Now that you have your API key, you can create a custom connector in the Power Platform.

  • Log into Power Apps or Power Automate.
  • In the left-hand menu, select ‘Data’ and then ‘Custom connectors’.
  • Click on ‘New custom connector’ and choose ‘Create from blank’.
  • Name your connector (e.g., “Chat GPT Connector“) and click on ‘Continue’.

Step 3: Define the Connector’s General Settings

  • Set the Host to `api.openai.com`.
  • Under the Base URL, enter ` /v1/chat/completions`.

Find out more about the latest endpoint used (https://platform.openai.com/docs/overview)

Step 4: Configure Authentication

  • Navigate to the ‘Security’
  • Select ‘API Key’ as the authentication type.
  • In the ‘Parameter label’, enter ‘API Key’.
  • In the ‘Parameter name’, enter ‘Authorization’.
  • In the ‘Location’, select ‘Header’.

Step 5: Define the API Call

  • Go to the ‘Definition’ tab and click on ‘New action’.
  • Name your action (e.g., “GetGPTResponse“) and provide a description.
  • In the ‘Request‘ section, click on ‘Import from sample’.

  • Select ‘POST’ as the verb and use the URL (the endpoint provided by OpenAI)
  • In the headers, add `Authorization` : `Bearer {API_Key}`.
  • In the body, define the necessary parameters such as `prompt`, `max_tokens`, etc.

Step 6: Test the Connector

  • Save your connector and move to the ‘Test’ tab.
  • Enter the required parameters and click ‘Test operation’.
  • If the setup is correct, you should see a successful response from the API.

Using the Chat GPT Connector in Power Apps and Power Automate

Power Apps

  • Open Power Apps and create a new or existing app.
  • Navigate to ‘Data’ and click ‘Add data’.
  • Select your custom Chat GPT connector.
  • Use the connector in your app by calling the defined action (e.g., `Get GPT Response`) in your app’s logic.

Power Automate

  • Open Power Automate and create a new flow.
  • Add a trigger to your flow (e.g., ‘When an HTTP request is received’).
  • Add an action and select your custom Chat GPT connector.
  • Configure the action parameters and integrate the output with other actions in your flow.

Conclusion

By following this guide, you can create a custom Chat GPT connector that enhances your Power Platform solutions. Whether you are building a chatbot in Power Apps or automating tasks in Power Automate, integrating AI opens up endless possibilities. Remember to refer to the OpenAI API documentation for more details on the available parameters and capabilities.

Have you tried integrating AI into your Power Platform solutions? What’s been your biggest challenge so far? Drop a comment or reach out—I’d love to hear how you’re using ChatGPT in your projects!

Happy building!

Dela, signing out!

Read more recent blogs

Get started on the right path to cloud success today. Our Crew are standing by to answer your questions and get you up and running.