How to use ChatGPT.(Power Automate Desktop)

08/07/2023

Japanese version.

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.

ParameterValue
URLhttps://api.openai.com/v1/completions
MethodPOST
Acceptapplication/json
Content typeapplication/json
Custom headersAuthorization:Bearer %APIkey%
Request body{
"model": "text-davinci-003",
"prompt": "%UserInput%",
"max_tokens": 2024,
"temperature": 0,
"top_p": 1
}
Encode request bodyOFF

Set up a Convert JSON tocustom object Action and set the JSON parameter to %WebServiceResponse%.

ChatGPT answers are set to %JsonAsCustomObject['choices'][0]['text']%.

---

Links

ChatGPT Articles

Tips(Power Automate Desktop)