You are on page 1of 13

Pega integration with Chat Gpt

Implementation

We will integrate Pega with chat gpt, open Ai Api.

Requirement:

1. Pega Personnel Edition


2. Postman Api testing Tool
3. Open Api Account and Key

Steps:
Step 1: Sign up on to Open Ai and go to Documentation
Link: https://openai.com/api/
Step 2: Select a model and Endpoint URL
Here we are Selecting the below end point URL
Url: POST https://api.openai.com/v1/completions
Model: Completion
Documentation Url:
https://platform.openai.com/docs/api-reference/completions
Step 3: Open postman paste the below URL
https://api.openai.com/v1/completions
Select Post Method

Step 4: Add 2 headers in the Header Tab in Post Man


Content-Type: application/json
Authorization: Bearer Api Key from Open Ai Account
Note: The Bearer keyword is important to add Infront of the Api key
Step 5: once All the Above are Done copy the Payload from the Documentation
Screen from open Ai and add paste it in the Body tab in
Postman.
Payload:
{
"model": "text-davinci-003",
"prompt": "Say this is a test",
"max_tokens": 7,
"temperature": 0,
"top_p": 1,
"n": 1,
"stream": false,
"logprobs": null,
"stop": "\n"
}

Step 5: Click on the Send button in postman if all the steps are good
We get a 200 status with Response as below
Response:

{
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "text_completion",
"created": 1589478378,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nThis is indeed a test",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}

The highlighted part is the output of our Configuration.

-----------------------------------Post Man Configuration Complete -----------------------------------------

Now We Have to Integrate the Api with Pega Using Connect Rest:
Steps
Step 1: log into Pega and go to Dev portal
Step 2: Open the Connector Rest integration wizard
By clicking on Configure—integration—connectors—Create Rest integration

Step 3: Add Name of the Connector and Endpoint URL and the Two Headers

Endpoint URL: https://api.openai.com/v1/completions


Content-Type
Authorization
Step 5: Click next in the Second screen add a name for the Connector and Select Post
Method

Step 6: Click next and in the 3rd, screen Click on Add Rest Response and test the
connection
By providing the Request payload and check the response try to get
Status: 200
Request:

Response:
Step 7: Click on next and Create the Connector by click Create on the Next Screen.

Step 8: Now We need to Create the Ui screens and Add the Connector logic to the Ui
Using an activity.
Step 9: Create a case type and add a Stage (Any name) and add a step to configure the
view using a Section

Step 10: Create a Section with the Request and Response and a Button
Step 11: All set now the joining link is the activity.

Step 12: Create the Activity and test the results


Inside the Activity we need a Serialize Data transform as the api
Accepts json request so we need to convert the clipboard details of
Pega to a json payload.
Step 13: Add the Activity to the Button with Action click and Event Refresh section
Include the Activity in the refresh section.
On refresh the Response will be Shown in the Section inside a Text area.
So finally, we get the output as Response.

------------------------------Integration
complete----------------------------------------
Important Note:

You Need to create a Text property to hold the Request payload


as json, which is get from the Data transform

The param.jsonData has to be provided to this property check


Step 4 of the Activity

This Property has to be created under Request class for my App


example my class is: DX-DXN-Int-ChatGpt-ChatAPI_Request

And provide it in the Request in the Connector Config Shown


Below:

------------------------------End-----------------------------

Still No Able to implement:

Connect with me on Linkedin. I would help you out.


My Linkedin Link Below:

https://www.linkedin.com/in/bibhash-kalita-b477aa9b/

You might also like