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: 
mpineyro
Explorer
How can we leverage the technology behind ChatGPT to interact with 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 is due to the enormous content it handles it is unlikely that it will offer information not accessible over the Internet.

It’s in the conversational interface where a significant breakthrough can truly be observed.

OpenAI's innovative approach has led to a significant leap in the capability of Large Language Models (LLM) to learn patterns and linguistic structures from large amounts of text in various domains. These models can generate coherent text based on the provided context.

Searching for ways to leverage this technology along with SAP products, we came across a previous entry on this blog describing an interesting integration scenario between ChatGPT and S/4HANA. In this article, I will introduce a similar scenario but implemented 100% in SAP BTP.

Scenario description


A customer emails an inquiry about the status of a Purchase Order. An automated process periodically checks the inbox for new emails and for every new email it determines if the request is aimed at knowing the status of a purchase order. If so, it extracts the relevant data from the body of the email and invokes S/4HANA’s Sales Order API and gets the status of the corresponding Sales Order. The system then composes an email emulating a customer service agent and provides the requested data.

Architecture:



architecture


OpenAI Text Completion API

 

OpenAI’s Text Completion API provides the core functionality of GPT-3, a generative language model. Through it, it is possible to complete and generate coherent and high-quality text. This API allows applications to perform tasks such as:

  • Text generation

  • Language translation

  • Conversation

  • Information retrieval


 

For this scenario we will use the Text Completion API for two tasks:

 

  1. Process email messages and determine if they are inquiries about the status of a purchase order. If so, we will also use it to generate a JSON structure with two fields: Customer name and Purchase Order number

  2. Compose a response email based on the data retrieved from S/4HANA.


 

Integration between the input channel (email) and the ERP will be in BTP’s Integration Suite. To retrieve incoming emails, an email receiver adapter is configured as the first step of an iflow providing the connection parameters of the email server and the frequency at which the mailbox will be checked.


email receiver adapter


 

The Text Completion API calls are sent as HTTP Requests and for the first task we input the following prompt:
"Process the following text and convert it into a JSON object with properties 'purchase_order' and 'nombre', assigning the value of the purchase order to 'purchase_order' and the name of the person signing the text to 'nombre' (name). Only do this if the text identifies a purchase order number."

And this is the data structure GPT sends back in the response:


 

GPT extracts relevant information from email


 

At this stage we have all the information we need to query the ERP for the status of the corresponding sales order. Since we want to access an On-Premise system from BTP we securely call S/4HANA’s Sales Order API through SAP Cloud Connector. We define a filter for this query to retrieve only the basic data of the sales order:

 


S/4HANA Sales Order API


 

Then we call Text Completion again but this time we prompt it to compose a response email based on the information obtained from the ERP:
“Compose e response email for a customer who inquired about the status of their purchase order from the company Invenzis, using the information provided below. The status data is indicated in the 'OverallDeliveryStatus' field, the customer's name is in the 'nombre' field, and the purchase order number is in 'PurchaseOrderByCustomer'."

 


GPT please generate a complete email response


 

it is worth noticing that with such a simple prompt we can generate a very coherent and well formatted block of text that can be sent to the customer without further revision. Until recently, developing a bot capable of performing like this required much more design and programming work.

Implementing the iflows


Let's see how to incorporate these three integrations (Email, GPT, and S/4HANA) into a single flow:


iflow


 

We need to implement a couple of Groovy Scripts to format the data (remove tabulation, special characters and tags from the text, etc)

Finally, let's see how the complete system works:

We send an email to the designated mailbox asking for the status of a specific purchase order:


email inquiry


 

And finally, the response generated by GPT based on the information obtained in S/4HANA and sent automatically vía email from Integration Suite:


response


We can easily adjust the content, tone, length, and other attributes of the response by providing more specific instructions. The purpose of this post is to demonstrate the potential of this for being used in the context of business applications.

Feel free to reach out in case you have any questions.
4 Comments
Labels in this area