Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
aashna_prakash
Advisor
Advisor

 

Introduction:


In today's digital age, customer reviews hold significant power in shaping buying decisions. For businesses striving to understand and improve customer experiences, harnessing the potential of AI becomes a game-changer. Sentiment Analysis is one area which can help businesses understand how customers perceive their products or services.

Based on this analysis, businesses can prioritize improvements, address issues, and make strategic decisions to enhance their offerings. Positive sentiments can be leveraged for marketing purposes, while negative sentiments can indicate areas needing improvement or damage control. At the same time, it helps users make an informed decision on which products they should buy.

There are many tools available today, that can help you build on this use case. However, the purpose of this blog is to showcase how this can be accomplished using No-Code tools and by leveraging SAP AI Core for Generative AI capabilities.

This ensures that citizen developers with no coding expertise or who can sometimes feel overwhelmed by the complexities of programming, are able to build applications within few hours.Also professional developers can quickly prototype with drag and drop ease and minimal configurations.

Today, I will take you through the process of creating a full stack application with SAP Build Apps and Generative AI that helps perform sentiment analysis on product reviews.

Let's quickly dive into the details.

Solution Architecture:

At its core, this app organizes products and their associated reviews, offering a comprehensive overview. It allows users to enter a product review and then categorizes it into positive, negative, or neutral review using Open AI’s ChatGPT to perform sentiment analysis.

The application consists of the following main parts:

    • SAP Build Apps – Web and Mobile application for the Frontend.
    • SAP Build Apps – Visual Cloud Functions for the Backend.
    • SAP AI Core.

GenAI1.drawio.png

 

 

Let's get started - 

Prerequisites

    • You should have access to SAP Build Apps on your SAP BTP Subaccount.
    • Pre-created destinations for Northwind OData Service and AI Core in BTP.

First, we will create an application backend for the reviews.



Create an entity Reviews with the following fields.




Create a Visual Cloud Function to return the counts of positive , negative and neutral reviews for each product.

    1. In the Functions Tab, click on Create New. Set the name to reviewCount.
    2. Under configuration, select the Reviews Entity.
    3. Click on End execution (on the right), and then on Execution Finished.
    4. Under Output values, click Add value, and set the following:

5. Click Set formula and enter the following formula:

GROUP(outputs["List records Reviews / Records listed"].records,item.productId,{productID:key,positive:COUNT(SELECT(items, item.sentiment == 3)), negative:COUNT(SELECT(items, item.sentiment == 1)), neutral: COUNT(SELECT(items, item.sentiment == 2))}) 

6. Deploy the backend.

Please refer to this blog for more details on how to create Visual Cloud functions.


 Next, we create a web application project from the SAP Build Lobby.




Enable BTP Authentication.

    • Go to the "Auth" Tab in project.
    • Select SAP BTP Authentication.

Add integration for the Northwind OData Service.

    • Under the "Data" tab, click on "Add Integration".
    • Select "BTP Destination".
    • Search for the Northwind destination.
    • Configure and enable the "Products" entity and save.

Add Integration for AI Core.

    • Under the "Data" Tab, click on "Create Data Entity" under SAP Build Apps classic data entities.
    • Select BTP Destination Rest API Integration.
    • Set Data Entity Name – AICoreLLM.
    • Select BTP Destination name.
    • Set 2 additional Common Request Headers.
    • Enable Create Mode.
    • Make following changes and save the entity.

Add Integration for the Reviews backend.
    • Under the "Data" tab, click on "Add Integration".
    • Select Cloud Functions.
    • Select Product Review Analysis Backend.(The project created in step 1).
    • Enable the Data Entity and save.

Now, let's build the Products List.

    • Create a data variable for the products resource - Products1.
    • Create an app variable for the review counts - reviewCounts.
    • We will create a composite component for the product.
      Refer to this tutorial on how to create one. Instead of the star rating in the above tutorial, we will use counts for positive, negative and neutral reviews. Create properties positiveReviewCount, negativeReviewCount and neutralReviewcount for the component.
    • Bind the composite component to the products data.
      FieldBinding
      Repeat withThe data variable Products1
      Title labelData item in repeat: current.ProductName
      positiveReviewCountDEFAULT(FIND_BY_KEY(appVars.reviewCounts,"ProductID", STRING(repeated.current.ProductID)).positive,0)
      negativeReviewcountDEFAULT(FIND_BY_KEY(appVars.reviewCounts,"ProductID", STRING(repeated.current.ProductID)).negative,0)
      neutralReviewcountDEFAULT(FIND_BY_KEY(appVars.reviewCounts,"ProductID", STRING(repeated.current.ProductID)).neutral,0)
      Image SourceYou can choose any image of your choice

      Products UI should look like this -

Next, we build the Product Details Page.

    • Create a new page and name it – Product Details.
    • Under "Page Parameter", add the following page parameters.
      FieldTypePurpose
      productIDTextThe product to be displayed on the product page, received when the user clicks on a certain product in the list of products

    • Add Data Variable Reviews1 for the resource Reviews.
    • Add Data Variable Product1 for a single data record.
    • In the logic pane, create the below logic flow.
    • Add Filtering and Sorting.
    • Add Navigation to this Page from the Products Page.
    • Add Container Product Details that will hold the details of the product such as name, quantity per unit, units in stock and unit price. Do the necessary bindings.
      FieldBinding
      TitleData Variable
      Product1.ProductName
      Text1Formula
      "Quantity Per Unit - "+data.Product1.QuantityPerUnit
      Text2Formula
      "Units in Stock - "+data.Product1.UnitsInStock
      Text3Formula
      "Price  - "+data.Product1.UnitPrice

    • Add "Add Review" button.
    • Add a container – Reviews Section to list all the reviews added so far for the product. Do the necessary bindings.
      PropertyBinding
      Primary labelData Item in Repeat
      Secondary LabelFormula - " - "+repeated.current.reviewedBy
      Arrow VisibleFalse
      Text3Formula - "Price  - "+data.Product1.UnitPrice
    • The page should look like this at this point.

Now, the final page  - Add Review.

    • Create a new page and name it – Add Review.
    • Under "Page Variables", add the following page variables:
      newReviewSentimenttextStore the sentiment of the review given.
      newReviewTextContains the text the user enters as a new review
      AIPayloadObjectRequest Payload for the AI Core API
    • Under "Page Parameter", add productID parameter.
    • Add an input and button. Give the input a label – Add Review.
    • The page should look like this -
    • Component Tap -> Set Page Variable -> Create Record -> Set Page Variable -> Create Record-> Navigate Back


      Open the logic pane and create the logic flow for the Submit button.
    • Set the properties for each node as follows.
      Set Page VariableVariable name – AIPayload
      Assigned Value – Object with Properties
      max_tokens - 256
      top_p - 1
      temperature - 0
      model - gpt-35-turbo-16k
      n - 1
      stream - False
      messages - List of values

      [
      
      {
      
      role: "system",
      
      content: "You are a helpful assistant which does sentiment analysis."
      
      },
      
      {
      
      role: "assistant",
      
      content: "Return 3 for positive, 2 for neutral and 1 for negative."
      
      },{
      
      role: "user",
      
      content: pageVariable - newReview
      
      }
      
      ]
      Create RecordResource – AICoreLLM
      Record – Page variable - AIPayload
      Set Page VariableVariable Name – newReviewSentiment
      Assigned Value – Formula - outputs["Save the AICore Response"].response.choices[0].message.content
      Create RecordResource – Reviews
      Reviews – Object with properties
      Review – Page Variable – newReview
      ProductID – Page Parameter – ProductID
      sentiment – Formula - NUMBER(pageVars.newReviewSentiment)
      ReviewedBy – your name
      DateCreated – Formula - NOW()
Voila! Your application is ready.
Watch the video to see how the application looks and works.
https://sapvideoa35699dc5.hana.ondemand.com/?entry_id=1_k14o8346 

Conclusion:

Awesome, we were able to build a full stack application leveraging Gen AI capabilities in very less time. That’s the power of No-Code and Generative AI.
This use case is just an example of how easily one can integrate intelligence in our solutions and create value for customers. One can extend this app to further derive insights on top of the analysis done. For example, create charts / metrics to measure which product is the least or most bought/liked.

I would like to thank gunteralbrecht , jayadnure  for helping and guiding me in my learning journey. Special thanks to daniel.wroblewski for below blog posts which helped me understand SAP BUILD better –

With that, I come to the end of my very first blog.
Do let me know your thoughts in the comments section.



2 Comments