In this CodeLab, you will extend your application to call a test API from the SAP Leonardo Machine Learning functional services.

This codelab will explain how to quickly get an idea off the ground that requires integrating SAP Leonardo Machine Learning Foundation services found on SAP API Business Hub into an SAP Cloud Platform side-by-side extension using the SAP Cloud SDK. Please note that SAP Leonardo Machine Learning services in SAP API Hub are only intended for prototyping and not for production. For production, you would use the service provisioning via SAP Cloud Platform service binding or the service keys, both leveraging the monitoring and security infrastructure of the platform. In our application, we will use the translation service for the example implementation. To implement the integration with ML services, we will leverage the SAP Cloud SDK component that simplifies the integration.

What you'll learn

Go to SAP API Hub and choose "Log On" on the right top corner of the screen.

Type "translation" in the search and choose "Inference service for machine translation" from the found services.

Click Show API key.

By clicking "Show API Key", you can get the API key specific for your user to authenticate against the API and we will use it later in the configuration in SAP Cloud Platform.

Keep this window open, you will need this value in the next step.

Create a new destination configuration with the name sap_api_business_hub_ml in your SAP Cloud Platform account.

Use the following URL to connect to the sandbox system:

Also, add property API_KEY copied from SAP API Hub in the previous step. The final endpoint sap_api_business_hub_ml should look as follows:

To implement the integration with the created API Hub destination, find the package machinelearning in your project, where you will find the TranslateServlet class. This class contains the method doGet(), which does the translation from german to english language for the provided text in the input parameter. This servlet will be called from the application frontend every time, when a user clicks on a term, which is shown in german language on the screen.

In this method, we already provide the implementation and leave some commented out blocks of code accompanied with TODO comments. Those blocks of code are related to query building and execution. The query will be built to get the data from the SAP Leonardo Machine Learning service for text translation hosted in SAP API Hub.

Take a look at the TODOs comment, think how you would implement those steps. Now, uncomment commented out lines of code and make sure that you understand what is done in each block of code.

Can you figure out how the application will identify the URL to connect to get the translation results?

Push your changes into GitHub repository, as was explained in the previous steps of this code lab.

Finally, you will deploy the application in your development space in SAP Cloud Platform, Cloud Foundry using the Continuous Delivery Toolkit set up before.

Now, go to your Jenkins and start the build for your project again.

In the initial Jenkins page, choose your project.

Select the branch you want to build. At the moment you have just one master branch if you did just the steps suggested in this tutorial.

In the left menu trigger Build Now. This will start the build and deployment of the new version of the project located in your GitHub repository.

In the productive setup, it is recommended to trigger such builds automatically on each code change in the repository. This can be achieved by introducing a webhook on your GitHub repository.

When the application is deployed, you can drill down into the application, choose the link for the application and append /address-manager to it. You should be able to see the business partner coming back from the mock server and you should be able to translate their professions by clicking on them.

Congratulations! You have just finished this code jam.

What we've covered