#ChatGPT is in the news and creating a buzz around it. Many predicted that it is the next big thing after Google. Since ChatGPT is breaking the internet and everyone is trying to use it atleast once to do many tasks and seek fun.
In this guide we will show how you can integrate ChatGPT with UiPath by OpenAI.
ChatGPT have many different models like- List Model, Retrieve Model, Completions Model any many more.
Let’s see the demostration:-
- First we will use the Input Dialog activity to take the input from the user.
- Now we need to process the User Input , so we use the HTTP Request activity.
To use this activity, we need to install the below activity from Manage Packages.
Now,drag and drop the activity HTTP Request and click on Configure button.
Once you will click on configure button, you will see the below window.
The inputs will be configured from the Open AI ChatGPT
Lets see how to get the input from Open AI ChatGPT
- Open the API Reference page of OpenAI ChatGPT.
- Go to Authentication page and click on API Keys link to create new API key.
- Click on new secret key to create API key and copy the key to notepad for further use.
Note:- API key is confidential and should not be shared with anyone.
- We are using completion Model for this guide.
Copy the End point URL from here and paste it into Notepad.
Now, we use all the information from Notepad to the HTTP request input.
Once you are done, then click on ok.
Now, we have to set the pass the UserInput into the HTTP request activity for processing for which we will use the property Body & Body Format and store the response output into the variable.
Change the body format to application/json.
As the body format is in json , so we have to convert the input into json.so we will a create a new Variable “ChatGPTInput” of type JObject and initialize the variable.
Now we will use an assign activity and pass the userinput to the Completion parameters.
Pass the JObject variable into the Body.
Store the Output into ChatGPTOutput variable.
Now, lets print the output by using the Write Line activity.
Output-
Message box-
This output contain so many details , but we just need the output. So we will decode this json output into the relevant output.
- We will use the Deserialize Json activity to decode the json. We will pass the output variable i.e ChatGPTOutput as an input and change the variable type to JObject.
Now, we will use the Write line activity to print the output.
We can see now the output is converted into the Json format which is readable to the user.
As we are interested only in the output and not the rest of the details. so we can see the text in the below image contains our output which is in Array Choices. so, we deserialize this array.
We can see now the output is converted into the Json format which is readable to the user.
We can see now the output is converted into the Json format which is readable to the user.
- Use Deserialize Json Array activity and pass the array name.
- We will again use the write line to see the result.
Output-
- As there is only curly braces inside the Square bracket, it means there is only 1 element in an array i.e at index 0 and then we need to get the outout from text, so we will use the below methos to get the result.
Now, finally lets run the workflow.
I hope you like it !
Happy Automation