ChatGPT integration with Pega

This is a very basis use case, where you can get the idea how to integrate ChatGPT with Pega.

Demo video:

Login to ChtGPT website using the below URL

https://platform.openai.com/playground

Sign up and create an account

Continue – Then you will receive an email for verification. Then login with your id and password.

Now you click the account icon, Personal on top right corner, you will get View API keys

Click View API keys

Click- Create new secret key

Now go to the playground tab and click view code

Now login to Pega

Enter the following details:

Enter Name : Chat GPT Integration

Enter Endpoint URL :(https://api.openai.com/v1/completions)

Add  Headers: Authorization

Add a REST response

Enter Authorization value (Note: Add the keyword Bearer before API Key) From Chat GPT

Enter Name : Chat GPT Integration

Enter Endpoint URL :(https://api.openai.com/v1/completions)

Add Headers: Authorization

Bearer sk-dPa**********************************HgoDWPqLibFnJ

Request body:

{

  “model”: “text-davinci-003”,

  “prompt”: “What is Pega CDH”,

  “temperature”: 0.7,

  “max_tokens”: 256,

  “top_p”: 1,

  “frequency_penalty”: 0,

  “presence_penalty”: 0

}

Note:: You should get the response and if you get error — just create a new key and copy the json from the site- do not change it manually.

In general you should get the below response

Click – Next

Click – Create

Now open the D_ChatGPTIntegration

Add a parameter Question

Go to the Data source

Open Request Data transform <ChatGPTIntegrationRequestPOST>

Go to the parameters tab and add a parameter Question

Now change the Request Data Transform – change the prompt

Now go to the Data Page <D_ChatGPTIntegration> and Run it

You will see the data within the choices tag

Now lets create a case type <ChatGPTIntegration>

Add to fields

Question

Answer

Create a Data Transform

Primary.Answer = D_ChatGPTIntegration[Question:Param.Question].choices(1).text

Parameters tab – Question

Parameters

Now go to the section add a button

Add the details in the Submit button

Run the case <ChatGPTIntegration>

In the question, I wrote ‘write something’ – In the Answer – ChatGPT replied. Please check the demo video at the start of the blog.

This is the end of this article. Hope this will help you to achieve the integration with ChatGPT. Now you can do other use cases as well.