Skip to content

Commit d5027f8

Browse files
committed
review changes
1 parent cfa5191 commit d5027f8

3 files changed

Lines changed: 118 additions & 166 deletions

File tree

tutorials/ai-core-orchestration-consumption-opt/ai-core-orchestration-consumption-opt.md

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ print(cv_content)
8585

8686
**NOTE** : If you are continuing with the same project from the previous tutorial, skip steps 1 and 2. Otherwise, create a new project using the already deployed orchestration URL to access the Harmonized API.
8787

88-
For detailed installation and usage of the **SAP Cloud SDK for AI (JavaScript)**, visit the official [GitHub repository](https://github.com/SAP/ai-sdk-js/tree/main?tab=readme-ov-file#sap-ai-sdkorchestration). This page provides comprehensive steps to set up, integrate and test the SDK effectively in your projects.
88+
For detailed installation, please refer to the official documentation of [`@sap-ai-sdk/orchestration`](https://github.com/SAP/ai-sdk-js/tree/main/packages/orchestration) package.
8989

9090
- The [cv.txt](img/cv.txt) file, containing the resume content, must be added to the working directory. Use the following code to load the file content:
9191

@@ -96,8 +96,6 @@ import { readFile } from 'fs/promises';
9696

9797
const cvContent = await readFile('path/to/cv.txt', 'utf-8');
9898

99-
//Print file content
100-
console.log(cvContent);
10199
```
102100

103101
[OPTION END]
@@ -298,29 +296,29 @@ models = [
298296

299297
[OPTION BEGIN [JavaScript SDK ]]
300298

301-
The next step involves creating a template that specifies how the AI should handle the CV content. The template will include both `SystemMessage` and `UserMessage` components.
299+
The next step involves creating a template that specifies how the CV content should be handled. The template will include message components with different roles:
302300

303-
`SystemMessage`: Defines the AI assistant's role and instructions.
301+
`system`: Defines the AI assistant's role and instructions.
304302

305-
`UserMessage`: Represents the user's input to be processed.
303+
`user`: Represents the user's input to be processed.
306304

307305

308306
```javascript
309307

308+
import type { TemplatingModuleConfig } from '@sap-ai-sdk/orchestration';
309+
310310
// Define the system and user messages
311-
const templatingConfig = {
312-
templating: {
313-
template: [
314-
{
315-
role: 'system',
316-
content: 'You are a helpful AI assistant for HR. Summarize the following CV in 10 sentences, focusing on key qualifications, work experience, and achievements. Include personal contact information, organizational history, and personal interests.',
317-
},
318-
{
319-
role: 'user',
320-
content: 'Candidate Resume:\n{{?candidate_resume}}',
321-
},
322-
],
323-
},
311+
const templating: TemplatingModuleConfig = {
312+
template: [
313+
{
314+
role: 'system',
315+
content: 'You are a helpful AI assistant for HR. Summarize the following CV in 10 sentences, focusing on key qualifications, work experience, and achievements. Include personal contact information, organizational history, and personal interests.',
316+
},
317+
{
318+
role: 'user',
319+
content: 'Candidate Resume:\n{{?candidate_resume}}',
320+
},
321+
],
324322
};
325323

326324
```
@@ -448,25 +446,24 @@ For this tutorial, we use anonymization:
448446

449447
```javascript
450448

449+
import type { MaskingModuleConfig } from '@sap-ai-sdk/orchestration';
450+
451451
// Define the data masking configuration
452-
const dataMaskingConfig = {
453-
masking: {
454-
masking_providers: [
455-
{
456-
type: 'sap_data_privacy_integration',
457-
method: 'anonymization',
458-
entities: [
459-
{ type: 'profile-email' },
460-
{ type: 'profile-person' },
461-
{ type: 'profile-phone' },
462-
{ type: 'profile-org' },
463-
{ type: 'profile-location' },
464-
],
465-
},
466-
],
467-
},
452+
const masking: MaskingModuleConfig = {
453+
masking_providers: [
454+
{
455+
type: 'sap_data_privacy_integration',
456+
method: 'anonymization',
457+
entities: [
458+
{ type: 'profile-email' },
459+
{ type: 'profile-person' },
460+
{ type: 'profile-phone' },
461+
{ type: 'profile-org' },
462+
{ type: 'profile-location' },
463+
],
464+
},
465+
],
468466
};
469-
console.log('Data Masking configuration defined successfully.');
470467

471468
```
472469

@@ -681,6 +678,7 @@ for model in models:
681678
```javascript
682679

683680
import { buildAzureContentSafetyFilter } from '@sap-ai-sdk/orchestration';
681+
import type { FilteringModuleConfig } from '@sap-ai-sdk/orchestration';
684682

685683
const inputFilter = buildAzureContentSafetyFilter({
686684
Hate: 'ALLOW_ALL',
@@ -696,19 +694,20 @@ const outputFilter = buildAzureContentSafetyFilter({
696694
Violence: 'ALLOW_SAFE_LOW_MEDIUM'
697695
});
698696

699-
const filteringConfig = {
697+
const filtering: FilteringModuleConfig = {
700698
filtering: {
701699
input: { filters: [inputFilter] },
702700
output: { filters: [outputFilter] }
703701
}
704702
}
705703

706-
console.log('Content Filtering configuration defined successfully.');
707704
```
708705

709706
**NOTE** : Adjust thresholds for hate, sexual, self-harm, and violence categories based on your use case.
710707

711-
Multiple filters can be applied for both input and output. In this tutorial, we are using Azure Content Filter, but you can choose from the available providers based on your use case. For more information on using this and/or additional modules, please refer to the official documentation of [SAP Cloud SDK for AI (Javascript)](https://github.com/SAP/ai-sdk-js/tree/main/packages/orchestration).
708+
Multiple content filters can be applied for both input and output. In this tutorial, we use Azure Content Safety Filter, but you can choose from the available providers based on your use case. For more information, please refer to the official documentation of [`@sap-ai-sdk/orchestration`](https://github.com/SAP/ai-sdk-js/tree/main/packages/orchestration) package.
709+
710+
The `filtering` configuration created in this step will be used in the next step to initialize an `OrchestrationClient` and consume the orchestration service.
712711

713712
[OPTION END]
714713

@@ -901,9 +900,9 @@ By incorporating these optional modules, you can tailor your Response to meet or
901900

902901
[OPTION BEGIN [JavaScript SDK]]
903902

904-
**Generate Responses for Multiple Models**
903+
**Generate Responses with Multiple Models**
905904

906-
This step outlines the process of generating responses for a set of queries using different models. The `generateResponsesForModels()` function iterates through each model and executes queries with the created template.
905+
This step outlines the process of generating responses for a set of queries using different models. The `generateResponsesWithModels()` function iterates through each model and executes queries with the created template.
907906

908907
**Note**: Ensure that your orchestration deployment is in Running Status and ready to be consumed during this process.
909908

@@ -915,7 +914,7 @@ import { OrchestrationClient } from '@sap-ai-sdk/orchestration';
915914
const RESOURCE_GROUP = "YourResourceGroupId"; // Define the resource group, change this to your resource group name
916915

917916
// Generate responses from multiple models using OrchestrationClient
918-
async function generateResponsesForModels(cvContent) {
917+
async function generateResponsesWithModels(cvContent: string) {
919918
// Initialize OrchestrationClient asynchronously for list of models
920919
const responses = await Promise.all(
921920
models.map(async (model) => {
@@ -928,9 +927,9 @@ async function generateResponsesForModels(cvContent) {
928927
temperature: 0.6,
929928
},
930929
},
931-
...templatingConfig,
932-
...dataMaskingConfig,
933-
...filteringConfig
930+
templating,
931+
masking,
932+
filtering
934933
},
935934
{ resourceGroup: RESOURCE_GROUP }
936935
);
@@ -941,17 +940,13 @@ async function generateResponsesForModels(cvContent) {
941940
inputParams: { candidate_resume: cvContent },
942941
});
943942

944-
// Extract the response content and return it
945-
return {
943+
// Extract the response content and add it to list of responses
944+
return {
946945
model,
947946
response: response.getContent(),
948947
};
949948
} catch (error: any) {
950-
const errorDetails = {
951-
status: error.cause?.status || 500,
952-
message: error.cause?.response?.data || error.message,
953-
};
954-
console.error(`Error with model ${model}:`, errorDetails);
949+
console.error(`Error with model ${model}:`, error.stack);
955950
}
956951
})
957952
);
@@ -964,12 +959,15 @@ async function generateResponsesForModels(cvContent) {
964959
.join(''),
965960
'utf-8'
966961
);
962+
963+
return responses;
967964
}
968965

969966
// Example usage
970-
const modelResponses = await generateResponsesForModels(cvContent);
971-
console.log(`\n=== Responses for model: ${modelResponses.model} ===\n`);
972-
console.log(modelResponses.response);
967+
const modelResponses = await generateResponsesWithModels(cvContent);
968+
modelResponses.map(response => {
969+
console.log(`==== Response with Model: ${response.model} ====\n${response.response || 'No response available'}\n`);
970+
});
973971

974972
```
975973

0 commit comments

Comments
 (0)