[TIPS] Add Custom Connector for ChatGPT in Power Platform

 [TIPS] Add Custom Connector for ChatGPT in Power Platform


1. Create an API KEY from https://platform.openai.com/account/api-keys



2.  Go to make.powerapps.com to create a new custom connector from blank.

   


  Choose HTTPS for Schemee.

 Set Host to api.openai.com


3. Set Parameter name to Authorization, Set location to Header by default.



4. Add a new action for post method.


Click Import from sample

Set URL to https://api.openai.com/v1/completions

Set Header to Content-Type application/json

Add sample data

{

  "model": "text-davinci-003",

  "prompt": "What's the meaning of life?",

  "max_tokens": 100,

  "temperature": 0.9,

  "top_p": 0.7

}


5. Click Create Connector at the top.

6. Create a new connection in Test tab page.



You may test the connector on the Test page.


7. Copy all information in Body section of Response.

8. Go back to Definition stage, click "Add default response" in Response section.


9. Paste the info copied from Step 7 into Body section, click Import button.  
    No need to set Header section.


10. Finally, click "Update Connector" button at the top.



Now you can use the custom connector in Power Automate Flows or Canvas APPs.
Take Flow for example.

Add the connector from Custom page.


  Set the parameters:


Below is the test result:





Done.


Demo:






Example:

Create a Canvas APP to work with ChatGPT through custom connector.



4 comments:

  1. Got error message when click "create connector

    The request failed with client error: '{"Code":"","Message":"PUT https://power-apim-unitedstates-002.management.azure-api.net/subscriptions/ad336f23-5b09-4b00-b5ef-c16decdffe26/resourceGroups/apim-power-unitedstates-002/providers/Microsoft.ApiManagement/service/power-apim-unitedstates-002/apis/chatgpt-5fc37b768a52493046-5f5a24a3ee41492c56?import=true&protocols=https&path=apim/chatgpt-5fc37b768a52493046-5f5a24a3ee41492c56&api-version=2019-01-01 failed with BadRequest, content={\"error\":{\"code\":\"ValidationError\",\"message\":\"One or more fields contain incorrect values:\",\"details\":[{\"code\":\"ValidationError\",\"target\":\"representation\",\"message\":\"Parsing error(s): JSON is valid against no schemas from 'oneOf'. Path 'securityDefinitions.undefined', line 81, position 18.\"},{\"code\":\"ValidationError\",\"target\":\"representation\",\"message\":\"Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md (schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json).\"}]}}","Target":null,"Details":[],"Innererror":null}'. The correlation Id is '3d40d867-3dfd-46a0-8501-05bee438a481'.

    ReplyDelete
  2. Do you have an updated version for 3.5 turbo chatgpt

    ReplyDelete
  3. I am getting error like
    {
    "error": {
    "message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": null
    }
    }
    anybody could help me to overcome

    ReplyDelete
    Replies
    1. Please use Bearer in front of the API copied from Open AI portal. Eg: Bearer sk-LWdKKXK7JUJfzJAqo31zT3Blbk12fght567

      Delete