Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
FarooqAhmed
Participant
16,509
Integration of SAP CPI(BTP IS) with ChatGPT

Introduction

What is ChatGPT?

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 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 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 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 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 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 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 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 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 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 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 source from my trail account on SAP BTP IS


Modify the Message body also with the selected property value.


Image source from my trail account on SAP BTP IS


Final Integration Flow will look like:


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 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 source from my trail account on SAP BTP IS


Testing in POSTMAN:


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 source from my trail account on SAP BTP IS



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.

If ChatGPT is connected at one side of the SAP CPI(BTP IS) the other side we can have any SAP(ECC, S4/HANA, SuccessFactor,etc.,) or non-SAP systems to achieve the end to end integration.

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.

 
17 Comments
Labels in this area