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: 
dharamverma
Explorer
6,338

  • Introduction: This document describes the step-by-step guide to integrate ChatGPT with CPI or Cloud Integration.


Here, I am going to take a scenario where I will pass a description of image to CPI then CPI will pass it to ChatGPT and ChatGPT will send a link of requested image in response, that I will show in a HTML format.

 

But let’s understand first,

What Is ChatGPT: -

  • ChatGPT is a language model developed by OpenAI. It is based on the GPT (Generative Pre-trained Transformer) architecture, specifically GPT-3.5. It is designed to generate human-like responses based on the input it receives. The model has been trained on a vast amount of text data and is capable of understanding and generating coherent and contextually relevant text.


 

  • ChatGPT is optimized for conversational interactions and can be used in a wide range of applications such as chatbots, virtual assistants, customer support systems, and more. It can understand natural language input and generate responses that simulate human-like conversation.


 

  • The model works by taking a prompt or a series of messages as input and generating a response based on its understanding of the context. It uses a transformer-based neural network architecture that leverages self-attention mechanisms to capture relationships between words and generate high-quality text.


 

  • While ChatGPT is capable of generating impressive responses, it is important to note that it is a language model and lacks real-world knowledge or true understanding. Its responses are generated based on patterns and correlations learned from the training data. Therefore, it may occasionally produce incorrect or nonsensical answers.


 

To integrate with ChatGPT, you would typically follow these steps:

 

  1. Determine Integration Scope: Identify the specific use case or application where you want to integrate ChatGPT. Determine the purpose, functionality, and requirements of the integration.


 

  1. Choose an API or SDK: OpenAI provides an API that allows you to interact with ChatGPT programmatically. You can use the OpenAI API to send input messages and receive model-generated responses. Alternatively, OpenAI might offer SDKs or libraries for specific programming languages that simplify the integration process.


 

  1. Design Conversation Flow: Define the conversation flow and logic for your integration. Decide how messages will be structured, how context will be maintained, and how you will handle user inputs and model responses. Plan for any additional features you want to incorporate, such as error handling or user context tracking.


 

  1. API Authentication and Setup: Sign up for an account with OpenAI and obtain the necessary authentication credentials, such as an API key or access token.


 

  1. API Requests: Use the API or SDK to send messages to ChatGPT and receive responses. Format the input messages as per the API specifications, including information such as the conversation history, user inputs, and any other relevant context.


 

  1. Process and Present Responses: Receive the model-generated responses from the API and process them as needed. Extract the relevant information and present it to the user in your desired format, such as text on a website, chat bubbles in a messaging app, or voice responses in a voice assistant.


 

  1. Iterative Testing and Improvement: Test your integration thoroughly to ensure it meets your requirements and provides the desired user experience. Iterate on the design, adjust parameters, and fine-tune the integration as necessary based on user feedback and observed performance.


How to get access of ChatGPT

  1. Open https://chat.openai.com/auth/login?next=/chat and click on sign up(Figure 1)


Figure 1

 

  1. Choose any one option to create your account (Figure 2)


Figure 2

 

  1. Once you signed up then go to https://platform.openai.com/account/api-keys click on create new secret key, which is required in integration with any system. (Figure 3)


Figure 3

 

  1. Now give any name and press “create secret key”.(Figure 4)


Figure 4

 

  1. Copy API or secret key for further use in CPI.


 

 

ChatGPT API references

  • API references link: https://platform.openai.com/docs/api-reference

  • ChatGPT’s API receive request and send response in JSON format.

  • Content type would be application/json.

  • For Authentication, APIKEY must send as a bearer token, for example.


Send a header Authorization: Bearer <Your API key>

 

      How to Integrate CPI with ChatGPT


Let’s create an iflow called “ChatGPT2getImage”.

  1. Create an iflow like below picture (Figure 5)


Figure 5

 

  1. This would be my URL where I will send a description of an image in query parameter.


https://<tenantID>.hana.ondemand.com/http/ChatGPT?desc=”A black audi car”

  1. As soon as request will come to iflow, a groovy script will read query parameter and it will convert it into property with same name and value.(Figure 6)


Figure 6

 

  1. "Content Modifier 1" will add two headers. (Figure 7)



  • Authorization Bearer <APIKey>

  • Content-type application/json


Figure 7

 

And create request JSON payload, payload will be created with property “desc”(Figure 😎


                            Figure 8

 

  1. Now we are good with request payload and header, So let's make a http call to openai(Figure 9)



                 Figure 9

 

  1. In the next step, I will convert JSON payload into XML  (Figure 10)


Figure 10

 

  1. Sometimes we can get multiple options, please see the sample response payload in (Figure 11)


Figure 11

 

  1. I want to read all the responses, that is why I am using “iterating splitter” (Figure 12)


Figure 12

 

  1. "Content Modifier 2" is reading url from XPATH and putting it in property URL (Figure 13)


Figure 13

 

  1. "Content Modifier 3" will set body in html format of image reading from URL (Figure 14)


Figure 14

 

  1. Next step is Gather, where i am concatenating all payloads from all iterations. (Figure 15)


Figure 15

 

  1. "Content Modifier 4" will set the content type as text/html and HTML as a payload where I am adding concatenated payloads from the previous step as an image source.(Figure 16)


Figure 16

 

  1. Deploy the iflow and let's try from Chrome.(Figure 17)


Figure 17

 

  1. Enter credentials (Figure 18).


Figure 18

 

  1. I am going to hit https://<tenantID>.hana.ondemand.com/http/ChatGPT?desc=”A black audi car” URL and here you can see the response.(Figure 19)


Figure 19

 

 

Conclusion: After reading this blog, you have learnt that what is ChatGPT, where it can be used and how to integrate it with any system or CPI.

 

 
Labels in this area