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: 
agyilmazturk
Explorer
In this blog series, I will try to explain how to use SAP Build Apps to create a maintenance notification app and integrate it with ChatGPT briefly. I will also explain how to connect the app with SAP Backend Systems such as SAP ERP or S/4HANA.









ENHANCING MAINTENANCE EFFICIENCY: SAP BUILD AND CHATGPT INTEGRATION FOR STREAMLINED MAINTENANCE NOTIFICATION APPS


Part 1 – Building a Maintenance Request app using SAP Build

Part 2 – Integrating ChatGPT with SAP Build

Part 3 – Integrating with a Backend System

In my first blog, I have tried to set the foundation for an exploration of SAP Build’s prowess in developing a Maintenance Notification app using SAP Build Apps. I have also briefly explained the options in SAP for the Maintenance Process and why did I select SAP Build Apps for the demo. If you didn’t read the first part, you can find the link above.

Getting Started with ChatGPT


Since there are a lot of resources that explains what is ChatGPT, I have decided to skip explaining what is ChatGPT and how it works. But please keep in mind that, you could use any other language model or even build your own model to integrate with SAP Build Apps, as long as there are APIs that we can leverage.


ChatGPT Free Trial


In our case, we select to use ChatGPT, therefore, you will need to create a free trial account for OpenAI, if you want to try by yourself. If that’s the case, you can sign up via openAI’s website. At the moment, you will get a $18 Credit for 3 months at the moment to try APIs for ChatGPT in scenarios like this.


API Keys for OpenAI APIs


Once you setup your account you can go to OpenAI platform and create your API Key which you’ll be needing for the integration. Here is the link for creating the API keys.

Summarize Maintenance Request Description to 40 Chars


If you are using SAP for some time, you would already know that in SAP usually there are two types of texts;

  • The Short Text : Which is most often limited to 40 Chars

  • The Long Text : This is stored as an object in SAP without any limits.


In our demo app, we have designed a description field for Maintenance Request which is a long text. So you can chose to have a separate field for the short text which should be limited to 40 characters or you can truncate the first 40 characters of our long text to use a short text. The short text is usually important because in SAP we mostly see the short text in reports since it is not a good idea to try to fit a limitless field (long text) in a ALV List or any other kind of tabular report.

Therefore, I will try to showcase how we can ask ChatGPT to summarize the long description of Maintenance Request into 40 Chars here.

ChatGPT APIs


There are a lot of APIs which OpenAI already provides for chat, audio, images etc. Upon these we can use two different API in our case to summarize a sentence into 40 chars;

Here is the first example using the completions api;


Completions API


Or you can also use the chat API as well;


Chat API


Feel free to use any of it, I will continue with using the 2nd example in our case. When you try the API, make sure you use your secret key as a Token;


API Authorization


Once you try the API, you should get a response similar to below;
{

"id": "chatcmpl-8RlKhcgmiWs4BclRyYWj8sMNwJHIC",

"object": "chat.completion",

"created": 1701627495,

"model": "gpt-3.5-turbo-0613",

"choices": [

{

"index": 0,

"message": {

"role": "assistant",

"content": "Level transmitter malfunction causing PSD."

},

"finish_reason": "stop"

}

],

"usage": {

"prompt_tokens": 45,

"completion_tokens": 6,

"total_tokens": 51

},

"system_fingerprint": null

}

Now we are ready to use it in the Build Apps now.

Integrating ChatGPT API with SAP Build Apps


In order to use the API in your app, you will need to navigate to Data and create Data Entity for your app, here you can create the Data Entity as REST API direct integration;


Create Data Entity for Chat Completion API


Here you will need to provide the Resource ID with the base URL and add your secret key;


Rest API - Base


Or even better you can store your key in an app variable as well;


App Variables


Once you are done with the Base setting, you can enable the Create Method, test it based on the Postman Request Body and then you can set the schemas from the successful API response.

After creating the Data Entity, we can now call it from the application. So here is my logic that I assigned to the Request Button when it is tapped;


Button Logic


I know it looks a little messy, but let me explain what it does;

When the button is tapped, first I check if the maintenance request description is longer than 40 chars, if it’s not I just move it to the short text field and clear the long text field. If it’s longer, than I ask the user if they want it summarized, if so than we can make a call to OpenAI API and if the User likes the summary and accepts it than I assign it to the Short Text field and keep the long text and than create the notification, notify the user and navigate back to initial screen.

Here you can see it in action;

https://youtube.com/shorts/jFObfVJAf1Q?feature=share

Again, I really hope you have enjoyed reading. In the next blog, we will focus on integrating the app with a Backend System such as SAP ERP or S/4HANA.

If you have any queries, let me know in comment or get in touch with me at LinkedIn!
Labels in this area