Put yourself in the shoes of a poetry slam manager who uses a poetry slam management application to manage the events. You want to easily create events with creative titles and descriptions. For the title and description proposal, the Partner Reference Application uses generative artificial intelligence (generative AI or genAI) based on large language models (LLM).
SAP has introduced a certification program for partner applications developed on SAP BTP using the generative AI hub. This program includes checks for Responsible AI compliance. It enables partners to offer trusted, compliant, and enterprise-ready applications powered by AI services, leveraging SAP’s expertise in business data insights. Additionally, the SAP Global AI Ethics Policy and the SAP AI Ethics Handbook provide guidance on applying the SAP AI Policies.
Furthermore, the SAP generative AI hub offers capabilities like Data Masking to support data protection and privacy implementation.
-
Enhance the poetry slam service.
-
Enhance the poetry slam service definition.
-
Add a new action named createWithAI to the PoetrySlams entity. This action creates a new poetry slam event and uses generative AI to propose a title and description.
@(cds.odata.bindingparameter.collection) @(UI.IsAIOperation: true) // Add the AI Icon to the action button action createWithAI( @( title: '{i18n>languageInput}', mandatory: true, Common:{ ValueListWithFixedValues: false, ValueList : { $Type : 'Common.ValueListType', CollectionPath: 'Language', Parameters : [ { $Type : 'Common.ValueListParameterInOut', ValueListProperty: 'name', LocalDataProperty: language, }, { $Type : 'Common.ValueListParameterDisplayOnly', ValueListProperty: 'code' }, { $Type : 'Common.ValueListParameterDisplayOnly', ValueListProperty: 'descr' } ] }, } ) language : String(50), @( title: '{i18n>tagsInput}', UI.Placeholder: '{i18n>placeholder}', mandatory: true ) tags : String(100), @( title: '{i18n>rhymeInput}', UI.ParameterDefaultValue: true ) rhyme : Boolean, ) returns PoetrySlams;
-
Add the Language entity from the sap.common.Languages module.
//Languages entity Language as projection on sap.common.Languages;
-
-
Copy the srv/lib/genAI.js file with the genAI class to your project.
-
Extend the srv/poetryslam/poetrySlamServicePoetrySlamsImplementation.js service implementation file with the implementation of the action.
-
Import the genAI class.
const GenAI = require('../lib/genAI');
-
Add the action implementation.
// Entity action: Create a poetry slam with generative artificial intelligence srv.on('createWithAI', async (req) => { const genAI = await GenAI.init(); const response = await genAI.callOrchestrationChatCompletion( req.data.tags, req.data.language, req.data.rhyme, req ); // In case the orchestration call could not be started, no draft will be created if (!response) return null; const poetrySlamDraft = await GenAI.createPoetrySlamWithAI( response, req, srv, db ); return poetrySlamDraft; });
-
-
Add UI texts for the action parameter dialog into the srv/i18n/i18n.properties file.
# ------------------------------------------------------------------------------------- # AI languageInput = Select the language in which you want the title and description to be generated tagsInput = Add some tags to describe the generated title and description rhymeInput = Generate the description in rhymes placeholder = For example: creative, funny -
Add the message texts for the action error handling into the srv/i18n/messages.properties file.
ACTION_AI_NO_ACCESS = Access to SAP AI Core service isn’t possible. Please reach out to your application provider. ACTION_AI_SETUP = The AI feature is setting up. Please try again shortly. ACTION_AI_MISSING_PARAMETERS = Please enter a language and tags. ACTION_AI_INVALID_PARAMETERS = Invalid parameters. Please check your input.
-
-
Enhance the SAP Fiori elements UI of the Poetry Slams application.
-
Enhance the LineItem section of the app/poetryslams/annotations file.
{ $Type : 'UI.DataFieldForAction', Action: 'PoetrySlamService.createWithAI', Label : '{i18n>createWithAI}' }, -
Add the UI text for the button into the /app/poetryslams/i18n/i18n.properties file.
createWithAI = Create with Slamtastic AI
-
-
Add the required npm modules as dependencies to the package.json file of your project.
-
Open a terminal.
-
Run the
npm add @sap-ai-sdk/orchestrationcommand. -
Run the
npm add @sap-ai-sdk/prompt-registrycommand.
-
Add the SAP AI Core service as a resource in the mta.yaml file.
```yaml
modules:
- name: poetry-slams-srv
requires:
- name: poetry-slams-aicore
- name: poetry-slams-mtx
requires:
- name: poetry-slams-aicore
resources:
# AI Core Service
- name: poetry-slams-aicore
type: org.cloudfoundry.managed-service
parameters:
service: aicore
service-plan: extended
```
-
Run the
npm installcommand in your project root folder to install the required npm modules. -
Build and deploy the application.
Now it's time to take you on a guided tour through the generative artificial intelligence feature of the Poetry Slam Manager:
-
Open the SAP BTP cockpit of the customer subaccount.
-
Open the Poetry Slams application.
-
Choose Create with Slamtastic AI to create a new poetry slam with a proposed title and description from generative artificial intelligence.
-
Select a language.
-
Add one or more tags that describe the content and style of the proposed title and description. Examples are funny and creative.
-
The parameter rhyme is defaulted. Stay with the default to get a text that is a rhyme.
That's it! You have created a CAP NodeJS application, deployed it to SAP BTP, added an SAP S/4HANA Cloud Public Edition and enhanced it to add a generative artificial intelligence feature.
If you had issues finishing all the stepsm, don't worry. You can jump back to the overview page Sync Point 2, 3 and 4.