Introduction
In today’s data-driven world, making informed business decisions is crucial, and leveraging data from business objects (like purchase order, maintenance order) can significantly enhance decision-making processes. However, much of this valuable data often remains latent due to its sheer volume and complexity.
Blog post series on Leveraging Dynamic Application Generation and GenAI for Real-Time Business Insights:
Business Value & overview of the entire use-case/application (click here)Comprehensive guide for setting up the application (this blog)
Langchain Summarization Techniques & Leveraging GenerativeAI Hub via Custom Model (click here)
In this blog post, I’ll explore an innovative approach to transforming latent data from business objects into actionable insights. By utilizing a single configuration file, you can dynamically create an end-to-end application for summarizing any business object. This application includes domain, service, and UI components, all generated dynamically from a single config file maintained by the application developer. This approach enables the summarization of multiple business objects simultaneously, unlocking their full potential for better business decisions.
In the above architecture, the application accesses APIs for the necessary business objects (SAP Solutions or third-party) via the destination service through its app logic layer. Based on the config file created by the end user, the application logic will dynamically generate the domain, service, and UI components on the fly. The data retrieved through the destination service is then processed by the summarization chain, which applies techniques such as stuff, map-reduce, or refine depending on the type of data and tokens required.
Let’s get started!
Pre-requisites
1. SAP BTP global account setup with the subscription to following services:
SAP AI Core Service SAP Cloud Logging Service SAP Authorization and Trust Management Service SAP BTP, Cloud Foundry Runtime SAP Build Work Zone, standard edition SAP Connectivity Service Destination Service SAP HTML5 Application Repository Service for SAP BTP SAP HANA Cloud
2. Access to the required Business System like SAP S/4HANA, SAP S/4HANA Cloud, and others.
Identify the APIs
To begin with, let’s identify the APIs for the necessary business object to consume in the application, you can use the following ways:
SAP Business Accelerator HubSAP Help PortalSAP Discovery Center
These three resources can help us identify the relevant API necessary for the use case, which will be further used for summarization.
In this blogpost, I’ll be focusing on two business objects i.e. Equipment/Maintenance Order and Purchase Orders from SAP S/4 HANA System. Here are the APIs for the same:
Api hub Equipment URL: Equipment APIApi hub Maintenance Order URL: Maintenance Order API Api hub Purchase Order URL: Purchase Order API
Setting up the destination
In the sample application, we are fetching data from different business systems like SAP S/4HANA Cloud, SAP S/4HANA, and more. To facilitate API calls, you’ll require the destination service.
For activating APIs on the SAP S/4HANA system, you can refer the documentation below and proceed to set up destinations on the BTP (as shown below):
On-Premise: Consume Remote Services from SAP S/4HANA using CAP Cloud: Establishing Connectivity between SAP S/4HANA Cloud and SAP BTP Create Destination: Create Destination on SAP BTP
To connect to Generative AI Hub and access the LLMs, we need to create a destination. You can refer to the documentation below and follow the instructions to set up the destination on SAP BTP (as shown below):
Leave Policy Compliance Verification Assistant(Follow 1-3 steps)
Creation of Config File
Now that the destination is set up, let’s set-up the project and configure the configuration file which will be used to dynamically create the end-to-end application on fly.
Let’s start by cloning the project:
git clone https://github.com/SAP-samples/real-time-business-insights-with-genai
Navigate inside srv/config folder to find the objectMappingConfig.json where configurations related to the desired business object will be made.
The basic layout to be maintained in the config is as follows:
{
“<your-business-system>”: {
“BusinessObjects”: [
{
“ObjectName”: “<your-api-entity-name>”,
“ObjectNameLabel”: “<your-api-entity-label>”,
“destinationName”: “<your-btp-destination-name>”,
“getUrl”: “<your-api-url>”,
“searchFields”: [
“<field1>”,
“<field2>”,
…
],
“keyFields”: [
“<key-field>”
],
“isListPageUI”(To be set to false, in case of object Page): “<true/false>”,
“summaryType”: “<map_reduce/refine>”,
“dependentObject” (Optional Param): “<your-dependent-api-entity-name>”,
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”,
“label”(Optional, to be given to enable field on UI): “<fieldLable>”,
“isSummarize”(Optional, to be given to summarize field): true
},
“<field2>”: {
“type”: “<field2Type>”,
“label”: “<field2Label>”
},
…
},
“expand”(Optional Param): [
{
“<your-expand-api-entity-name>”: {
“ObjectName”: “<your-expand-api-entity-name>”,
“type”: “Composition”,
“keyFields”: [
“<key-field>”,
…
],
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”
},
“<field2>”: {
“type”: “<field2Type>”,
“label”(Optional, to be given to enable field on UI)
“isSummarize”(Optional, to be given to summarize field): true
},
…
},
“expand”(Optional Param): [
{
“<your-expand-api-entity-name>”: {
“ObjectName”: “<your-expand-api-entity-name>”,
“type”: “Composition”,
“keyFields”: [
“<key-field>”,
…
],
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”
},
“<field2>”: {
“type”: “<field2Type>”,
“label”(Optional, to be given to enable field on UI)
“isSummarize”(Optional, to be given to summarize field): true
},
…
}
}
}
]
}
}
]
}
]
},
…
}
In the above config, let us also understand what each property signifies:
Property Definition Business System It contains the Business System Name like SAP S/4HANA Cloud, SAP S/4HANA On-Prem Object Name It contains the API entity Name Object Name Label It contains the API entity Label Destination Name It contains the Destination Name, created on BTP Get URL It contains the API URI Path Key Fields It contains primary field of the API entitySearch Fields It contains the field required for filter bar isListPageUI It contains true or false value, which indicates true in case of List Page and false in case of Object Page dependentObject It contains API entity Name in case of a dependent object which is not directly connected to the given API entity summaryType
It contains the summary type if the business object needs to summarized based on stuff, map-reduce or refine technique List Fields
It contains the list fields to be displayed on the UI Expand (Optional)
It contains composition relation to the entity’s dependent entity List Fields (expand)
It contains the list fields for the dependent entities and contains properties type (String/Integer/Date) and label to be displayed on UI
Let’s see an example to better understand on how to maintain the config file.
Use-case-1: Plant Maintenance:
In this scenario, we will utilize two API entities: Equipment and Maintenance Orders. Although these entities are theoretically significant, there is no entity relationship (OData navigations) through APIs. Here, Equipment will serve as the main entity displayed on the List Page UI, while Maintenance Order will function as its dependent entity, with its data shown on the Object Page UI. This setup illustrates that each piece of equipment can have multiple maintenance orders, highlighting how summarizing maintenance history can provide clear, actionable insights, thereby facilitating better decision-making for specific equipment.
The config file is as follows: objectMappingConfig.json
Use-case-2: Purchase Orders
In this scenario, we will utilize a single API entity: Purchase Order and it’s Purchase Order Notes which is present as child entity (OData navigation exists via $expand). Here, Purchase Order will be the main entity displayed on the List Page UI, while the Purchase Order Note will serve as its dependent/expand entity, with its data shown on the Object Page UI. This setup demonstrates how each Purchase Order can have multiple notes maintained by purchase managers/operators for the supplier. Summarizing these purchase order notes allows for quick and efficient decision-making without being overwhelmed by data.
The config file is as follows: objectMappingConfig.json
Using the above two use-case scenarios, we can clearly see how to create configuration files for multiple business objects. In the first case, we utilize two API entities that are theoretically significant but lack an entity relationship through APIs. In the second case, we have a single API entity with its dependent entity present in the expand field. This approach ensures that both main entities and their dependent entities are effectively summarized, providing actionable insights for better decision-making and efficient data management.
Testing the application locally
Now, as we have set-up our configuration file with the details of the required Business Object, let’s test the application locally.
Before running the application locally, we need to generate the apps for business objects mentioned in our config file.
Run the below command to generate the apps:
npm run generate-bo-ui
In the apps folder, we can see apps being generated based on our configuration file as shown below:
BTS (Behind-the-scenes): The apps are dynamically generated by using summary app as the base and making the necessary changes to the files required for generating multiple apps based on their configurations. You can find the code for dynamic app creation in apps/generateBOAppUIs.js
To test the CAP Application on the local environment, we would have to bind the SAP Destination Service, SAP Connectivity Service(required only for On-Prem system), Identity Authentication and deploy to sqlite db(for local development).
Before binding the service we need to login to cloud-foundry and select the account, space where we want the deployment to happen.
Run the below command to login into cloud-foundry(cf)
cf login -a <your-cf-api-endpoint>
Create service instances on BTP to consume locally:
cf cs destination lite sap-bos-dest
cf cs xsuaa application sap-bos-auth
cf cs connectivity lite sap-bos-connectivity
Run the below commands to bind the services:
cds bind -2 sap-bos-auth –for development
cds bind -2 sap-bos-connectivity –for development
cds bind -2 sap-bos-dest –for development
cds deploy –to sqlite –for development
To test the summarization of business object, update the .cdsrc.json file with:
GenAI Hub destination name Chat Model deployment URL Chat Model resource groupChat Model API version
{
“requires”: {
“GENERATIVE_AI_HUB”: {
“CHAT_MODEL_DESTINATION_NAME”: “AICoreAzureOpenAIDestination”,
“CHAT_MODEL_DEPLOYMENT_URL”: “<your-deployment-URL>>”,
“CHAT_MODEL_RESOURCE_GROUP”: “<your-resource-group-name>”,
“CHAT_MODEL_API_VERSION”: “<your-model-version>”
},
“SUMMARIZATION_CONFIG”: {
“MAX_TOKENS”: “500”
},
“AICoreAzureOpenAIDestination”: {
“kind”: “rest”,
“credentials”: {
“destination”: “<your-destination-name>”,
“requestTimeout”: “300000”
}
},
“auth”: “xsuaa”,
“[production]”: {
“db”: {
“kind”: “hana”
}
}
}
}
Once all the services and DB is set-up, execute the command ‘cds watch’ to initiate the server. In your browser open the link http://localhost:4004 and you should be able to see the landing page of your application(similar to below).
BTS (Behind-the-scenes): The service.cds and annotations.cds are dynamically generated on the fly, when the cds watch command is initiated, based on which the controller fetches and parses the response, to display the data on the UI from the mentioned business system(s) in the configuration file. You can find the code for dynamic service & annotation creation in srv/boConfigsTransformer.js and controller in srv/boDetailsController.js
For a better understanding of the scenario, please watch the demo video below.
Demo Video
Build & Deploy
Now that we have the CAP application running locally, let’s build & deploy it on BTP CF Environment.
Before deployment of the applicationapplication, we need to login to cloud-foundry (if not already done in the previous step) and select the account, space where we want the deployment to happen.
Run the below command to login into cloud-foundry(cf😞
cf login -a <your-cf-api-endpoint>
To build the application, run the below command:
npm run build
To deploy the application, run the below command:
npm run deploy
With this you’ll be able to see the application deployed in the specified BTP CF environment (as shown below).
Configure SAP Build Work Zone Site
Once the deployment is successful, let’s configure the application in the SAP Build Work Zone Site.
Navigate to the SAP BTP subaccount, where the deployment was done and Choose Services → Instances and Subscriptions on the left.
Locate the SAP Build Work Zone, standard edition under Subscriptions and choose Go to Application.
Choose Channel Manager on the left and refresh the HTML5 App entry there.
Add the Business Object mentioned in the configuration file to My Content.
In the given scenario above, I added the Equipment and Purchase Order to My Content.
Once added, navigate back to the Content Manager and Create a User Group and Name it as BO Summarization. Add the Equipment and Purchase Order app to the user group (as shown below) and click on Save.
Now let’s also create a User Role to access Equipment and Purchase Order app. Navigate back to the Content Manager and Create a Role and name it as SAP BOS Access. Add the Equipment and Purchase Order app to the role (as shown below) and click on Save.
Note: Having a separate app for each object enables better control over application access. This approach allows for the creation of different roles with specific sets of apps, which can then be assigned to various business user personas in SAP Build WorkZone.
Assign User Role & Test the deployed application
Now in the previous step, as we created SAP BOS Access role to access the Equipment and Purchase Order App in the Site, let’s assign this role to our user, to access the 2 apps in the site created.
For this, Navigate to your BTP Account. Under the security Tab in Users, search for your user and click on Assign Role Collection.
Search for SAP_BOS_App_Access and assign it to your user.
Well with that, it’s all set now to access our deployed applications on the Site we created earlier.
Let’s Navigate once again to the SAP Build Work Zone, and under the Site Directory we should be able to see our Business Object Summarization Site.
Upon Navigation to the site, we should be able to see Tiles for Equipment and Purchase Order and able to run the application as well.
Technical Details (Optional)
In this section of the blog post, I will delve into the behind-the-scenes process of dynamically creating an application based on the provided configuration file.
Let’s take a deep dive at what each file does and understand the intricacies of this scenario:
boConfigsTransformer.js:
This file is responsible for creating service entities and UI annotations. It begins by reading the business object details from the configuration file, then prepares the entity fields and service definitions at the service layer. At the UI layer, it sets up the selection fields, list item fields, and more for both the List Page and Object Page. Finally, it transforms all these definitions together and sends them to the controller for consumption.
boDetailsController.js:
This file is responsible for parsing the business object (BO) configuration and the service and UI definitions received from the transformer. It prepares the API requests and manages navigation to fetch data from the business object source system specified in the configuration file. Once the data is collected, the response is parsed for display on the UI. Additionally, fields marked for summarization are collected at all levels and passed to the summarize() function to generate the historical summary.
GenAIHubChatLLM.js:
Since the Summarization Chain provided by LangChain requires connection to a Chat Model to fetch historical summaries, it must pass through the generative AI Hub for secure data transfer. Direct connection to the summarization chain is not possible, so we need to create a custom model. This custom model will connect to the cap-llm-plugin, which provides a direct connection to thegenerative AI hub without exposing confidential data to the LLM. This is facilitated through the generative AI hub destination set up earlier.
Summary Folder:
This folder consists of 2 files utilGenerateSummary.js and utilSummarizationController.js.
utilGenerateSummary.js:
This file defines a module for summarizing text documents using Langchain’s Summarization Chain. It includes functions to count and split tokens, prepare text for summarization, and determine the appropriate summarization method. The module connects to the GenAI Hub via a custom chat model for secure data transfer, loads the summarization chain, and generates a summary. It optimizes the process by adjusting the summarization type and splitting large texts into chunks.
utilSummarizationController.js:
This file contains functions for checking the existence of historical summaries and configuring summarization parameters. checkSummaryExists( ) queries the BusinessObjectSummarizations entity in DB to check if a summary exists for a given business object. summarizeConfig generates configuration parameters for summarization types (stuff, refine, map_reduce) based on user settings. It utilizes LangCchain’s PromptTemplate to create structured prompts ensuring summaries meet specified word limits, tones, and structures.
For more details on creating a custom model and exploring various summarization techniques, please refer to Part 3 of the blog post.
To customize “Customize summarization” pop-up (fragment): Navigate to the ext/fragment directory within the app/summary/webapp folder. Here, you can modify the pop-over according to your specific requirements.
Conclusion
We hope this blog post has provided insights into unlocking the hidden potential of SAP business objects by summarizing their latent data into actionable insights. By dynamically creating an end-to-end application from a single configuration file, you can streamline the summarization process and enhance decision-making capabilities across LOBs. With the step-by-step approach provided, you can efficiently implement this solution and begin leveraging the full value of your business data.
At last, I would like to extend my heartfelt gratitude to my colleagues whose insights, support, and collaboration have been invaluable throughout this PoC. So Special thanks to @Ajit_K_Panda for his guidance and @Aryan_Raj_Sinha for his valuable contributions in PoC development and @PVNPavanKumar and @anirban-sap for his leadership support.
IntroductionIn today’s data-driven world, making informed business decisions is crucial, and leveraging data from business objects (like purchase order, maintenance order) can significantly enhance decision-making processes. However, much of this valuable data often remains latent due to its sheer volume and complexity. Blog post series on Leveraging Dynamic Application Generation and GenAI for Real-Time Business Insights:Business Value & overview of the entire use-case/application (click here)Comprehensive guide for setting up the application (this blog)Langchain Summarization Techniques & Leveraging GenerativeAI Hub via Custom Model (click here)In this blog post, I’ll explore an innovative approach to transforming latent data from business objects into actionable insights. By utilizing a single configuration file, you can dynamically create an end-to-end application for summarizing any business object. This application includes domain, service, and UI components, all generated dynamically from a single config file maintained by the application developer. This approach enables the summarization of multiple business objects simultaneously, unlocking their full potential for better business decisions. In the above architecture, the application accesses APIs for the necessary business objects (SAP Solutions or third-party) via the destination service through its app logic layer. Based on the config file created by the end user, the application logic will dynamically generate the domain, service, and UI components on the fly. The data retrieved through the destination service is then processed by the summarization chain, which applies techniques such as stuff, map-reduce, or refine depending on the type of data and tokens required. Let’s get started!Pre-requisites 1. SAP BTP global account setup with the subscription to following services: SAP AI Core Service SAP Cloud Logging Service SAP Authorization and Trust Management Service SAP BTP, Cloud Foundry Runtime SAP Build Work Zone, standard edition SAP Connectivity Service Destination Service SAP HTML5 Application Repository Service for SAP BTP SAP HANA Cloud 2. Access to the required Business System like SAP S/4HANA, SAP S/4HANA Cloud, and others.Identify the APIs To begin with, let’s identify the APIs for the necessary business object to consume in the application, you can use the following ways: SAP Business Accelerator HubSAP Help PortalSAP Discovery CenterThese three resources can help us identify the relevant API necessary for the use case, which will be further used for summarization. In this blogpost, I’ll be focusing on two business objects i.e. Equipment/Maintenance Order and Purchase Orders from SAP S/4 HANA System. Here are the APIs for the same: Api hub Equipment URL: Equipment APIApi hub Maintenance Order URL: Maintenance Order API Api hub Purchase Order URL: Purchase Order API Setting up the destination In the sample application, we are fetching data from different business systems like SAP S/4HANA Cloud, SAP S/4HANA, and more. To facilitate API calls, you’ll require the destination service. For activating APIs on the SAP S/4HANA system, you can refer the documentation below and proceed to set up destinations on the BTP (as shown below): On-Premise: Consume Remote Services from SAP S/4HANA using CAP Cloud: Establishing Connectivity between SAP S/4HANA Cloud and SAP BTP Create Destination: Create Destination on SAP BTP To connect to Generative AI Hub and access the LLMs, we need to create a destination. You can refer to the documentation below and follow the instructions to set up the destination on SAP BTP (as shown below): Leave Policy Compliance Verification Assistant(Follow 1-3 steps) Creation of Config File Now that the destination is set up, let’s set-up the project and configure the configuration file which will be used to dynamically create the end-to-end application on fly. Let’s start by cloning the project: git clone https://github.com/SAP-samples/real-time-business-insights-with-genai Navigate inside srv/config folder to find the objectMappingConfig.json where configurations related to the desired business object will be made. The basic layout to be maintained in the config is as follows: {
“<your-business-system>”: {
“BusinessObjects”: [
{
“ObjectName”: “<your-api-entity-name>”,
“ObjectNameLabel”: “<your-api-entity-label>”,
“destinationName”: “<your-btp-destination-name>”,
“getUrl”: “<your-api-url>”,
“searchFields”: [
“<field1>”,
“<field2>”,
…
],
“keyFields”: [
“<key-field>”
],
“isListPageUI”(To be set to false, in case of object Page): “<true/false>”,
“summaryType”: “<map_reduce/refine>”,
“dependentObject” (Optional Param): “<your-dependent-api-entity-name>”,
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”,
“label”(Optional, to be given to enable field on UI): “<fieldLable>”,
“isSummarize”(Optional, to be given to summarize field): true
},
“<field2>”: {
“type”: “<field2Type>”,
“label”: “<field2Label>”
},
…
},
“expand”(Optional Param): [
{
“<your-expand-api-entity-name>”: {
“ObjectName”: “<your-expand-api-entity-name>”,
“type”: “Composition”,
“keyFields”: [
“<key-field>”,
…
],
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”
},
“<field2>”: {
“type”: “<field2Type>”,
“label”(Optional, to be given to enable field on UI)
“isSummarize”(Optional, to be given to summarize field): true
},
…
},
“expand”(Optional Param): [
{
“<your-expand-api-entity-name>”: {
“ObjectName”: “<your-expand-api-entity-name>”,
“type”: “Composition”,
“keyFields”: [
“<key-field>”,
…
],
“listFields”: {
“<field1>”: {
“type”: “<field1Type>”
},
“<field2>”: {
“type”: “<field2Type>”,
“label”(Optional, to be given to enable field on UI)
“isSummarize”(Optional, to be given to summarize field): true
},
…
}
}
}
]
}
}
]
}
]
},
…
} In the above config, let us also understand what each property signifies:Property Definition Business System It contains the Business System Name like SAP S/4HANA Cloud, SAP S/4HANA On-Prem Object Name It contains the API entity Name Object Name Label It contains the API entity Label Destination Name It contains the Destination Name, created on BTP Get URL It contains the API URI Path Key Fields It contains primary field of the API entitySearch Fields It contains the field required for filter bar isListPageUI It contains true or false value, which indicates true in case of List Page and false in case of Object Page dependentObject It contains API entity Name in case of a dependent object which is not directly connected to the given API entity summaryType It contains the summary type if the business object needs to summarized based on stuff, map-reduce or refine technique List Fields It contains the list fields to be displayed on the UI Expand (Optional) It contains composition relation to the entity’s dependent entity List Fields (expand) It contains the list fields for the dependent entities and contains properties type (String/Integer/Date) and label to be displayed on UI Let’s see an example to better understand on how to maintain the config file. Use-case-1: Plant Maintenance: In this scenario, we will utilize two API entities: Equipment and Maintenance Orders. Although these entities are theoretically significant, there is no entity relationship (OData navigations) through APIs. Here, Equipment will serve as the main entity displayed on the List Page UI, while Maintenance Order will function as its dependent entity, with its data shown on the Object Page UI. This setup illustrates that each piece of equipment can have multiple maintenance orders, highlighting how summarizing maintenance history can provide clear, actionable insights, thereby facilitating better decision-making for specific equipment. The config file is as follows: objectMappingConfig.json List Page UI (Equipment)Object Page UI (Maintenance Orders)Use-case-2: Purchase Orders In this scenario, we will utilize a single API entity: Purchase Order and it’s Purchase Order Notes which is present as child entity (OData navigation exists via $expand). Here, Purchase Order will be the main entity displayed on the List Page UI, while the Purchase Order Note will serve as its dependent/expand entity, with its data shown on the Object Page UI. This setup demonstrates how each Purchase Order can have multiple notes maintained by purchase managers/operators for the supplier. Summarizing these purchase order notes allows for quick and efficient decision-making without being overwhelmed by data. The config file is as follows: objectMappingConfig.json List Page UI (Purchase Order)Object Page UI (Purchase Order Details (Notes))Using the above two use-case scenarios, we can clearly see how to create configuration files for multiple business objects. In the first case, we utilize two API entities that are theoretically significant but lack an entity relationship through APIs. In the second case, we have a single API entity with its dependent entity present in the expand field. This approach ensures that both main entities and their dependent entities are effectively summarized, providing actionable insights for better decision-making and efficient data management. Testing the application locally Now, as we have set-up our configuration file with the details of the required Business Object, let’s test the application locally. Before running the application locally, we need to generate the apps for business objects mentioned in our config file. Run the below command to generate the apps: npm run generate-bo-ui In the apps folder, we can see apps being generated based on our configuration file as shown below:BTS (Behind-the-scenes): The apps are dynamically generated by using summary app as the base and making the necessary changes to the files required for generating multiple apps based on their configurations. You can find the code for dynamic app creation in apps/generateBOAppUIs.jsTo test the CAP Application on the local environment, we would have to bind the SAP Destination Service, SAP Connectivity Service(required only for On-Prem system), Identity Authentication and deploy to sqlite db(for local development). Before binding the service we need to login to cloud-foundry and select the account, space where we want the deployment to happen. Run the below command to login into cloud-foundry(cf) cf login -a <your-cf-api-endpoint> Create service instances on BTP to consume locally: cf cs destination lite sap-bos-dest
cf cs xsuaa application sap-bos-auth
cf cs connectivity lite sap-bos-connectivity Run the below commands to bind the services: cds bind -2 sap-bos-auth –for development
cds bind -2 sap-bos-connectivity –for development
cds bind -2 sap-bos-dest –for development
cds deploy –to sqlite –for development To test the summarization of business object, update the .cdsrc.json file with: GenAI Hub destination name Chat Model deployment URL Chat Model resource groupChat Model API version {
“requires”: {
“GENERATIVE_AI_HUB”: {
“CHAT_MODEL_DESTINATION_NAME”: “AICoreAzureOpenAIDestination”,
“CHAT_MODEL_DEPLOYMENT_URL”: “<your-deployment-URL>>”,
“CHAT_MODEL_RESOURCE_GROUP”: “<your-resource-group-name>”,
“CHAT_MODEL_API_VERSION”: “<your-model-version>”
},
“SUMMARIZATION_CONFIG”: {
“MAX_TOKENS”: “500”
},
“AICoreAzureOpenAIDestination”: {
“kind”: “rest”,
“credentials”: {
“destination”: “<your-destination-name>”,
“requestTimeout”: “300000”
}
},
“auth”: “xsuaa”,
“[production]”: {
“db”: {
“kind”: “hana”
}
}
}
} Once all the services and DB is set-up, execute the command ’cds watch’ to initiate the server. In your browser open the link http://localhost:4004 and you should be able to see the landing page of your application(similar to below). BTS (Behind-the-scenes): The service.cds and annotations.cds are dynamically generated on the fly, when the cds watch command is initiated, based on which the controller fetches and parses the response, to display the data on the UI from the mentioned business system(s) in the configuration file. You can find the code for dynamic service & annotation creation in srv/boConfigsTransformer.js and controller in srv/boDetailsController.js For a better understanding of the scenario, please watch the demo video below. Demo VideoBuild & Deploy Now that we have the CAP application running locally, let’s build & deploy it on BTP CF Environment. Before deployment of the applicationapplication, we need to login to cloud-foundry (if not already done in the previous step) and select the account, space where we want the deployment to happen. Run the below command to login into cloud-foundry(cf😞 cf login -a <your-cf-api-endpoint> To build the application, run the below command: npm run build To deploy the application, run the below command: npm run deploy With this you’ll be able to see the application deployed in the specified BTP CF environment (as shown below). Configure SAP Build Work Zone Site Once the deployment is successful, let’s configure the application in the SAP Build Work Zone Site. Navigate to the SAP BTP subaccount, where the deployment was done and Choose Services → Instances and Subscriptions on the left. Locate the SAP Build Work Zone, standard edition under Subscriptions and choose Go to Application. Choose Channel Manager on the left and refresh the HTML5 App entry there. Add the Business Object mentioned in the configuration file to My Content. In the given scenario above, I added the Equipment and Purchase Order to My Content. Once added, navigate back to the Content Manager and Create a User Group and Name it as BO Summarization. Add the Equipment and Purchase Order app to the user group (as shown below) and click on Save. Now let’s also create a User Role to access Equipment and Purchase Order app. Navigate back to the Content Manager and Create a Role and name it as SAP BOS Access. Add the Equipment and Purchase Order app to the role (as shown below) and click on Save. Note: Having a separate app for each object enables better control over application access. This approach allows for the creation of different roles with specific sets of apps, which can then be assigned to various business user personas in SAP Build WorkZone.Assign User Role & Test the deployed application Now in the previous step, as we created SAP BOS Access role to access the Equipment and Purchase Order App in the Site, let’s assign this role to our user, to access the 2 apps in the site created. For this, Navigate to your BTP Account. Under the security Tab in Users, search for your user and click on Assign Role Collection. Search for SAP_BOS_App_Access and assign it to your user. Well with that, it’s all set now to access our deployed applications on the Site we created earlier. Let’s Navigate once again to the SAP Build Work Zone, and under the Site Directory we should be able to see our Business Object Summarization Site. Upon Navigation to the site, we should be able to see Tiles for Equipment and Purchase Order and able to run the application as well. Technical Details (Optional) In this section of the blog post, I will delve into the behind-the-scenes process of dynamically creating an application based on the provided configuration file. Let’s take a deep dive at what each file does and understand the intricacies of this scenario: boConfigsTransformer.js: This file is responsible for creating service entities and UI annotations. It begins by reading the business object details from the configuration file, then prepares the entity fields and service definitions at the service layer. At the UI layer, it sets up the selection fields, list item fields, and more for both the List Page and Object Page. Finally, it transforms all these definitions together and sends them to the controller for consumption. boDetailsController.js: This file is responsible for parsing the business object (BO) configuration and the service and UI definitions received from the transformer. It prepares the API requests and manages navigation to fetch data from the business object source system specified in the configuration file. Once the data is collected, the response is parsed for display on the UI. Additionally, fields marked for summarization are collected at all levels and passed to the summarize() function to generate the historical summary. GenAIHubChatLLM.js: Since the Summarization Chain provided by LangChain requires connection to a Chat Model to fetch historical summaries, it must pass through the generative AI Hub for secure data transfer. Direct connection to the summarization chain is not possible, so we need to create a custom model. This custom model will connect to the cap-llm-plugin, which provides a direct connection to thegenerative AI hub without exposing confidential data to the LLM. This is facilitated through the generative AI hub destination set up earlier. Summary Folder: This folder consists of 2 files utilGenerateSummary.js and utilSummarizationController.js. utilGenerateSummary.js: This file defines a module for summarizing text documents using Langchain’s Summarization Chain. It includes functions to count and split tokens, prepare text for summarization, and determine the appropriate summarization method. The module connects to the GenAI Hub via a custom chat model for secure data transfer, loads the summarization chain, and generates a summary. It optimizes the process by adjusting the summarization type and splitting large texts into chunks. utilSummarizationController.js: This file contains functions for checking the existence of historical summaries and configuring summarization parameters. checkSummaryExists( ) queries the BusinessObjectSummarizations entity in DB to check if a summary exists for a given business object. summarizeConfig generates configuration parameters for summarization types (stuff, refine, map_reduce) based on user settings. It utilizes LangCchain’s PromptTemplate to create structured prompts ensuring summaries meet specified word limits, tones, and structures. For more details on creating a custom model and exploring various summarization techniques, please refer to Part 3 of the blog post. To customize “Customize summarization” pop-up (fragment): Navigate to the ext/fragment directory within the app/summary/webapp folder. Here, you can modify the pop-over according to your specific requirements.Conclusion We hope this blog post has provided insights into unlocking the hidden potential of SAP business objects by summarizing their latent data into actionable insights. By dynamically creating an end-to-end application from a single configuration file, you can streamline the summarization process and enhance decision-making capabilities across LOBs. With the step-by-step approach provided, you can efficiently implement this solution and begin leveraging the full value of your business data. At last, I would like to extend my heartfelt gratitude to my colleagues whose insights, support, and collaboration have been invaluable throughout this PoC. So Special thanks to @Ajit_K_Panda for his guidance and @Aryan_Raj_Sinha for his valuable contributions in PoC development and @PVNPavanKumar and @anirban-sap for his leadership support. Read More Technology Blogs by SAP articles
#SAP
#SAPTechnologyblog