Introduction to using ChatGPT from Power Automate Desktop.
Overall view of Flow
Robin(for copy and paste)
It can be copied and pasted into Power Automate Desktop.
SET APIkey TO $'''sk-'''
Display.InputDialog Title: $'''Enter your question for ChatGPT.''' InputType: Display.InputType.SingleLine IsTopMost: False UserInput=> UserInput ButtonPressed=> ButtonPressed
Web.InvokeWebService.InvokeWebService Url: $'''https://api.openai.com/v1/completions''' Method: Web.Method.Post Accept: $'''application/json''' ContentType: $'''application/json''' CustomHeaders: $'''Authorization:Bearer %APIkey%''' RequestBody: $''' {
\"model\": \"text-davinci-003\",
\"prompt\": \"%UserInput%\",
\"max_tokens\": 2024,
\"temperature\": 0,
\"top_p\": 1
}''' ConnectionTimeout: 30 FollowRedirection: True ClearCookies: False FailOnErrorStatus: False EncodeRequestBody: False UserAgent: $'''Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20100312 Firefox/3.6''' Encoding: Web.Encoding.AutoDetect AcceptUntrustedCertificates: False ResponseHeaders=> WebServiceResponseHeaders Response=> WebServiceResponse StatusCode=> StatusCode
Variables.ConvertJsonToCustomObject Json: WebServiceResponse CustomObject=> JsonAsCustomObject
Display.ShowMessageDialog.ShowMessage Title: $'''ChatGPT''' Message: JsonAsCustomObject['choices'][0]['text'] Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed2
Flow creation steps
Get the ChatGPT API key (secret key) in beforehand.
Create the variable %APIkey% in the Set Variable Action and set the API key.
Mark the %APIkey% variable as sensitive information.
Set up a Display input dialog Action to ask the user to enter a question into ChatGPT.
Set up a Invoke web service Action and set the parameters as follows.
Parameter | Value |
---|---|
URL | https://api.openai.com/v1/completions |
Method | POST |
Accept | application/json |
Content type | application/json |
Custom headers | Authorization:Bearer %APIkey% |
Request body | { "model": "text-davinci-003", "prompt": "%UserInput%", "max_tokens": 2024, "temperature": 0, "top_p": 1 } |
Encode request body | OFF |
Set up a Convert JSON tocustom object Action and set the JSON parameter to %WebServiceResponse%.
ChatGPT answers are set to %JsonAsCustomObject['choices'][0]['text']%.
---