How can we leverage the technology on which ChatGPT is based to interact with S/4HANA?
In this post I describe an integration scenario that allows us to automatically respond with information coming from S/4HANA.
ChatGPT is one of the most widely used applications today by a wide variety of users when searching for information on almost any topic. While to some extent the rapid adoption of this application as a source of reference is due to the sheer volume of content it handles, it is unlikely to offer information that is not accessible on the Internet.
Where you can really see substantial progress is in the conversational interface.
Openai’s innovative approach has resulted in a significant leap in the ability of Large Language Models (LLMs) to learn linguistic patterns and structures from large amounts of text in various domains. These models can generate coherent text based on the context provided.
In looking for ways to leverage this technology together with SAP products we came across a previous post to this blog describing an interesting integration scenario between ChatGPT and S/4HANA. In this article we are going to present a similar scenario but 100% implemented in SAP BTP.
A system was implemented that interacts via email with customers who send inquiries about the status of a Purchase Order. The system periodically checks an email inbox, decides whether the customer’s request is intended to know the status of their purchase order and if so, extracts the relevant data from the body of the email to make a call to S/4HANA and obtain the status of the purchase order indicated. Once the information is received from the ERP, the system creates an email emulating a customer service agent and provides the requested data.
OpenAI Text Completion API
The API called “Text Completion” provides the core functionality of OpenAI’s GPT-3 generative language model. Through it, it is possible to complete and generate consistent and high quality text. This interface allows our applications to perform tasks such as:
- Text generation
- Language translation
- Search for information
With this in mind, we will use the Text Completion API for two tasks:
- Process the email messages interpreting if it is a query for the status of a purchase order. If so, we will ask you to generate a JSON structure with two specific data: Customer name and Purchase Order number.
- From the S/4HANA response with the corresponding sales order information, compose a response email.
The integration between the incoming channel (email) and the ERP will be done through iflows developed in Integration Suite. To retrieve incoming emails, an email receiver adapter is configured, in which we provide the connection data to the email server as well as the frequency with which we want to check if new messages have arrived.
email receiver adapter
The interaction with the Text Completion API is done through HTTP Requests and the instruction we give it is as follows:
“process the following text and convert it to a JSON object with properties ‘purchase_order’ and ‘name’ and assign the purchase order value in ‘purchase_order’ and the name of the signer of the text in ‘name’. Only do this if the text identifies a purchase order number”.
The following is the data structure that we obtain in response:
classify email and extract relevant information
At this point we already have the information we need to send to the ERP to obtain the status of the sales order corresponding to the PO indicated by our customer, therefore we proceed to make a call to the S/4HANA API. Since we want to access an On Premise system from BTP we will make the call to the ERP securely through the SAP Cloud Connector. We will define a filter for this query in order to retrieve only the basic data of the sales order:
S/4HANA Sales Order API Calling
Next we call Text Completion again, in this case to create a response email from the information obtained in the ERP. The instruction we give is as follows:
“make up a text oriented to a customer who consulted the company Invenzis for the status of his purchase order using the information below. The status data is in the ‘OverallDeliveryStatus’ field and the customer’s name is in the ‘name’ field and the purchase order number is in PurchaseOrderByCustomer:”
email generated by GPT
At this point it is worth clarifying that by means of a simple prompt or instruction as brief as the one above, we can dynamically generate a block of text that is totally coherent and with the right tone to send to the client. Until recently, getting a bot to generate such a response required much more design and programming work.
Let’s see how to incorporate these three integrations into a single flow: Email, GPT and S/4HANA:
Throughout the flow it is necessary to implement some Groovy Scripts to adapt the information to each of the processing stages (define headers, eliminate tabulation and special characters in the text, select message data, etc).
Finally let’s see how the whole system works:
We send an email to the box defined for queries:
Email sent by customer inquiring about purchase order status
Finally, the mail made by GPT from the information obtained in S/4HANA and sent from Integration Suite automatically:
Email received by customer
It should be clarified that we can easily adjust the content, tone, length, and other attributes of the response if we provide more specific instructions, in this case it is simply intended to demonstrate the potential of this technology to be used in the context of enterprise applications.
Feel free to contact me if you have questions about the scenario described in this post.
Original source: https://blogs.sap.com/2023/06/02/integracion-de-s-4hana-con-chatgpt/