ChatGPT is a language model developed by OpenAI. It is designed to understand natural language, generate human-like responses to a wide range of questions, and carry out various language-related tasks. It has been trained on a large corpus of text data and can understand a broad range of topics. Its purpose is to assist users in their quest for knowledge and provide them with informative and useful responses.

What is CPI(BTP-IS)?

CPI(BTP-IS) is a set of services and tools provided by SAP on its cloud-based Business Technology Platform (BTP) to enable integration between different systems, applications, and data sources. The key benefit of CPI(BTP IS) is that it enables organizations to quickly and easily integrate their systems, data, and applications without the need for extensive coding or custom development. This helps to streamline business processes, reduce costs, and improve operational efficiency.

How ChatGPT can be integrated?

ChatGPT can be integrated using APIs (Application Programming Interfaces) provided by OpenAI. The API can be used to send text inputs to ChatGPT and receive responses in real-time. Chatbot Platform Integration and Custom Integration using libraries and SDK also possible.

How CPI integrates with ChatGPT?

CPI interacts ChatGPT through HTTP requests using API Keys for authentication. ChatGPT has multiple APIs depending on the usage or self learning basis like Models, Completions, Edits, Images, Create Image Variations, Embeddings, Files, Fine-tunes and Moderations APIs

Note: All the available ChatGPT APIs can be integrated with SAP CPI but for demonstration will use the Completion API.

Integration of SAP CPI(BTP IS) with ChatGPT

Prerequisites:

  1. SAP BTP IS Tenant Access
  2. ChatGPT openai platform Access
  3. Postman Tool for testing

Step-1: Create a new secret key on ChatGPT  

After login to the account on https://platform.openai.com/account/api-keys goto API Keys and click on Create new secret key.

Image%20source%20from%20my%20account%20on%20platform.openai.com

Image source from my account on platform.openai.com

 

Step-2: Download the security certificate from respective ChatGPT API

For demo we will use the API “ https://api.openai.com/v1/completions” from other available APIs of ChatGPT.

Open the API url in any browser and click on the lock(HTTPS) icon from the address bar and select show certificate.

Export the root certificate and save to your local desktop.

Image%20source%20from%20my%20account%20on%20platform.openai.com

Image source from my account on platform.openai.com

Step-3: Upload the root security certificate in the SAP BTP IS(CPI)=>KeyStore

Login to BTP account and redirect to your Integration Suite home page. From the left side pane select the monitor artifacts options and open the Keystore page.

Click on Add dropdown option from right side top pane and select the Certificate option and upload the already downloaded security certificate from Step-1.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Step-4: Create a new Integration Flow under the desired package with appropriate naming convention.

From the left side pane design artifacts option select or create a package and create a new IFLOW.

We need to create a scenario of HTTPS sender adapter to HTTP receiver adapter with intermediate call on chatGPT API .

Step-5: Configure a sender HTTPS adapter as we will test it from Postman tool.

As per the requirement we can have any sender adapter which can able to provide the expected input text.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Provide the desired Address path which will be added to the deployed tenant URL.

Step-6:  Configure the JSON to XML converter as the input text from Postman will be provided as JSON.

As per the requirement we can have any format input can be sent from sender system which can be modified accordingly.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Remove the Namespace Mapping if selected.

In our case JSON to XML only is used as input from POSTMAN will be JSON and for further processing of exchange properties we will use XML .

Step-7: Configure the Content Modifier to set the Message Header, Exchange Property and Message Body.

The ChatGPT HTTP API will be called with Authorization and ContentType values in the Message Header

So accordingly provide the Header constant in the Content Modifier with Content-Type as application/json

And Authorization will be the Bearer (space) API key generated in the step-1

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

The sample input from source will be in the below JSON format

{

“prompt”: “Input Text here

}

In order to capture the Input “Prompt” value and prepare complete request to API  the exchange property will be configured with a “input” referring to the Xpath of the JSON converted XML field value.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

The original API HTTP call will be expecting the actual source input with its respective parameters. Those parameters and source input will be formulated in the Message Body.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Each ChatGPT API call will be processed based on the model name provided. In our case will provide the latest model “text-davinci-003” which is the most capable GPT-3 model. Can do any task the other models can do, often with higher quality, longer output and better instruction-following. And supports inserting completions within text. Also its trained with the internet content available upto Jun2021.

Step-8:  Configure a Request-reply with HTTP adapter receiver connection to ChatGPT API.

Provide the mandatory field values like Address of the ChatGPT API, Method as POST, Authentication as Client Certificate and the Request/Response headers. The Request headers can be given as * or Authorization|Content-Type  etc.

                     Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Step-9: Handling the API JSON response.

When any ChatGPT API is invoked with JSON request then there will be a JSON response which can be converted to XML to produce the desired field output.

Configure the JSON to XML converter to select the respective XML field values to be populated in the output.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Step-10: Configure the Content Modifier for converted XML payload.

Create a “output” property referring to the XML text field which will be only populated as final output.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Modify the Message body also with the selected property value.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Final Integration Flow will look like:

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Once the IFLOW is saved and deployed , go to the Managed Integration Content and get the endpoint which will be used in the source system to trigger a message to CPI.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

In order to view the traces in the CPI monitor message processing. Select the log level as Trace instead of default option Info.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Testing in POSTMAN:

Image%20source%20from%20local%20installed%20Postman

Image source from local installed Postman

Provide the CPI tenant endpoint URL for the created IFLOW along with the BTP account credentials in the Postman Authorization section.

For the sample input provided we have received the response accordingly from the chatGPT API.

Monitoring the IFLOW from CPI tenant with the trace enabled.

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Image%20source%20from%20my%20trail%20account%20on%20SAP%20BTP%20IS

Image source from my trail account on SAP BTP IS

Conclusion:

Any input text given to the ChatGPT API there will be cutting-edge language models working to understand and generate the response text. With the available ChatGPT APIs we can integrate them with CPI/any middleware to consume and provide more reliable response on top of AI.

Disclaimer:

This article is only for informational purpose that CPI can be integrated with the ChatGPT APIs also.

Only a integration of one API has been shown as an example but no limitations in any perspective.

 

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x