Consumption of GenAI models Using Orchestration - A Beginner's Guide
In this tutorial, we are going to learn the simple consumption of Gen AI models using the Orchestration.
Overview
You will learn
- How to inference GenAI models Using Orchestration
Prerequisites
Prerequisites
- BTP Account
Set up your SAP Business Technology Platform (BTP) account.
Create a BTP Account - For SAP Developers or Employees
Internal SAP stakeholders should refer to the following documentation: How to create BTP Account For Internal SAP Employee, SAP AI Core Internal Documentation - For External Developers, Customers, or Partners
Follow this tutorial to set up your environment and entitlements: External Developer Setup Tutorial, SAP AI Core External Documentation - Create BTP Instance and Service Key for SAP AI Core
Follow the steps to create an instance and generate a service key for SAP AI Core:
Create Service Key and Instance - AI Core Setup Guide
Step-by-step guide to set up and get started with SAP AI Core:
AI Core Setup Tutorial - An Extended SAP AI Core service plan is required, as the Generative AI Hub is not available in the Free or Standard tiers. For more details, refer to SAP AI Core Service Plans
Steps
This tutorial provides a basic introduction to using orchestration in SAP AI Core.
Orchestration in SAP AI Core is a managed service that enables unified access, control, and execution of generative AI models through standardized APIs, templating, and configurable AI workflow components.
You will learn how to deploy and configure orchestration to enable the consumption of multiple GenAI models within a single workflow.
Please note that:
- The model and model-version referenced in the tutorial may differ from the current offerings. Refer to the SAP Note for the list of available models.
- The AILaunchpad screenshots in tutorial may slightly vary from the current AILaunchpad UI.
We will walk through a step-by-step guide and demonstrate the orchestration flow using a resume processing use case. This real-world scenario highlights how different models can collaborate within a cohesive pipeline using orchestration.
Note: In SAP AI Core, orchestration deployment is available by default in the default resource group during the onboarding. For any new or additional resource groups, you must deploy a separate orchestration setup.
While orchestration in SAP AI Core offers capabilities such as data masking, content filtering, translation, and grounding, this tutorial focuses on the basic consumption flow using mandatory modules like templating and model configuration. Others modules are Optional and usage of those modules are covered in a separate tutorial.
By the end of this tutorial,
you will have a foundational understanding of orchestration through its minimal usage, focusing on practical application of templates and how to switch between different models using harmonized APIs.
Learn how to implement the solution using SAP AI Launchpad, Python SDK, Java, JavaScript, and Bruno.
Refer to the orchestration documentation for more information.
โข Open AI Launchpad.
โข Connect to your instance using your credentials.
โข Navigate to the desired Resource Group where you plan to deploy the orchestration.
For the detailed step follow the tutorial - Setup Generative AI Hub in SAP AI Launchpad
Installing sap-ai-sdk-gen
To install the SAP Cloud SDK for AI (Python) - generative package in your system, open your terminal or command prompt and run the following command.
pip install sap-ai-sdk-genOnce the package is installed, you need to configure proxy modules to use the large language models. We recommend setting these values as environment variables for AI Core credentials via a configuration file. The default path for this file is ~/.aicore/config.json.
Open Notepad and replace the placeholder values in the JSON file with your AI Core service keys, which you downloaded from BTP. Save the file by pressing Command + S. When prompted, navigate to ~/.aicore/ and save the file as config.json.
The configuration file should be:

โข Create a service key for your AI Core service instance and copy the generated JSON object.
โข Set the copied service key as the AICORE_SERVICE_KEY environment variable in your local environment. Maintaining a single-line format will prevent parsing errors.
AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","serviceurls":{"AI_API_URL":"..."}}'The SDK parses the service key from the environment variable to interact with the AI Core service.
โข Optionally, set the AICORE_HOME environment variable to override the default config path.
โข Install the required packages:
npm install @sap-ai-sdk/ai-api @sap-ai-sdk/orchestration dotenvโข For detailed setup and usage,refer to the official GitHub repository of SAP Cloud SDK for AI.
โข For detailed installation and usage of the SAP Cloud SDK for AI (JavaScript), visit the official GitHub repository and Documentation. This page provides comprehensive steps to set up, integrate and test the SDK effectively in your projects.
Tip:
โข Ways to load environment variables might vary based on the framework you are using.
โข For example, while the SAP Cloud SDK for AI (JavaScript) uses the dotenv library to load environment variables, NextJS uses a specific configuration to load them.
โข Installing JavaScript Kernel for Jupyter Notebooks: If you want to use JavaScript in Jupyter Notebooks, you can refer to Deno v1.37 blog post for detailed steps to install the Javascript kernel. Follow the instructions provided to set up the environment and enable JavaScript support in Jupyter.
โข Create a service key for your AI Core instance and copy the JSON object.
โข Create a .env file in the working directory from which you run the code. Add the following line using the copied JSON:
AICORE_SERVICE_KEY={"clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }โข IMPORTANT: The value of AICORE_SERVICE_KEY must be a single line, so remove any line breaks from the service key JSON.
โข This tutorial is designed for a Java maven project. Add the following dependencies to your project pom.xml file:
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>core</artifactId>
<!-- Use the latest version here -->
<version>${ai-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>orchestration</artifactId>
<!-- Use the latest version here -->
<version>${ai-sdk.version}</version>
</dependency>โข For other options of access configuration and detailed information on installation and usage of the SAP Cloud SDK for AI (Java), visit the official documentation platform. This page provides comprehensive steps to set up and integrate the SDK effectively in your projects.
Download and Import the Bruno Collection
Download the bruno_collections file
Navigate to the Bruno Collections section
Upload the .json file to import the collection. Follow the screenshot attached for reference

img 
img 
img
Set Environment Variables
From the imported collection, select the get_token query.
Click on “No Environment” and then select “Configure”.

- Populate the following environment variables with values from the service key:
- ai_auth_url โ url from the service key.
- ai_api_url โ serviceurls.AI_API_URL from the service key.
- client_id โ clientid from the service key.
- client_secret โ clientsecret from the service key.
- resource_group โ Specify a resource group name.

Save the environment configuration.
Click on “No Environment” in the top-right corner and select “Grounding-test”.

img
Generate the Token
Select the get_token request from the root folder of the imported collection.
Execute the request to generate the token.

img
NOTE: If the token expires at any point during execution, repeat this step to regenerate it.
Execute this step only if orchestration deployment is not available. Other wise skip this step and proceed to the next step
Consume LLM's in Generative AI Hub through Orchestration
As part of the SAP AI Core onboarding process, an
orchestration deploymentis automatically created in thedefault resource group.
This means you can start using orchestration in the Generative AI Hub right awayโno need to create a separate deployment.
In this step you will be:
- creating the configuration required for the orchestration deployment
- Creating the Orchestration deployment
Go to the Configuration section within your chosen Resource Group.

โข Fill in Deployment Details, Under configuration, input the following details:
Name: "orchestration"
Executable: "orchestration"
Scenario: "orchestration"
Version: "0.0.1"
โข Click Next after entering each detail.

When prompted, click on Create Deployment. Continue through the setup by clicking Next until you reach the deployment confirmation.

Once the deployment begins, continue to the status page. Verify that the Deployment Status changes to Running (see attached screenshot for reference).

โข Create a folder named orchestration, then navigate to this folder using VS Code.
โข Inside the folder, create a new file with any name but ensure it has the .ipynb extension.

You’ll create a configuration that defines the orchestration setup. Use the following code to initialize your configuration.
import time
import json
import os
from IPython.display import clear_output
from ai_core_sdk.ai_core_v2_client import AICoreV2Client
from ai_api_client_sdk.models.parameter_binding import ParameterBinding
from enum import Enum
# Create AI Core client instance
def create_ai_core_client(credCF):
set_environment_vars(credCF) # Ensure environment variables are set
return AICoreV2Client(
base_url=os.environ['AICORE_BASE_URL'],
auth_url=os.environ['AICORE_AUTH_URL'],
client_id=os.environ['AICORE_CLIENT_ID'],
client_secret=os.environ['AICORE_CLIENT_SECRET'],
resource_group=os.environ['AICORE_RESOURCE_GROUP']
)
ai_core_client = create_ai_core_client(credCF)
# Define scenario ID, executable ID, and configuration suffix
scenario_id = "orchestration"
executable_id = "orchestration"
config_suffix = "config-new" โฏ # Enter your configuration name
config_name = f"{config_suffix}-orchestration"
# Create a new configuration
config = ai_core_client.configuration.create(
โฏ โฏ scenario_id=scenario_id,
โฏ โฏ executable_id=executable_id,
โฏ โฏ name=config_name
)
print(f"Configuration created successfully with ID: {config.id} and Name: {config_name}") Note:
โข scenario_id and executable_id: Both are set to “orchestration” for this tutorial.
โข config_name: Choose a unique name for the configuration (e.g., “config-new-orchestration”)

With the configuration ID, you can proceed to deploy the orchestration and monitor its progress.
Create the Deployment:
Run the following code to create a deployment using the configuration ID obtained in Step 2.
# Create a deployment using the configuration ID from the previous cell
deployment = ai_core_client.deployment.create(configuration_id=config.id)
print(f"Deployment created successfully with ID: {deployment.id}") 
Monitor Deployment Status:
Execute the following code to monitor the deployment until itโs fully active. The status should eventually display as “Running”.
from ai_api_client_sdk.models.status import Status
def spinner(check_callback, timeout=300, check_every_n_seconds=10):
โฏ โฏ start = time.time()
โฏ โฏ while time.time() - start < timeout:
โฏ โฏ โฏ โฏ return_value = check_callback()
โฏ โฏ โฏ โฏ if return_value:
โฏ โฏ โฏ โฏ โฏ โฏ return return_value
โฏ โฏ โฏ โฏ for char in '|/-\\':
โฏ โฏ โฏ โฏ โฏ โฏ clear_output(wait=True)
โฏ โฏ โฏ โฏ โฏ โฏ print(f'Waiting for the deployment to become ready... {char}')
โฏ โฏ โฏ โฏ โฏ โฏ time.sleep(0.2)
# Define the callback to check if the deployment is ready
def check_ready():
โฏ โฏ updated_deployment = ai_core_client.deployment.get(deployment.id)
โฏ โฏ return updated_deployment if updated_deployment.status == Status.RUNNING else None
# Wait for the deployment to be ready
ready_deployment = spinner(check_ready)
print(f"Deployment is ready with status: {ready_deployment.status}") Result: The code will display a loading spinner until the deployment status updates to “Running.” Refer to the attached screenshot for confirmation.
Note: API note need to be added here

In this step, we will create an orchestration configuration using the @sap-ai-sdk/ai-api package of the SAP Cloud SDK for AI (JavaScript). For more information, refer to the official documentation. This configuration integrates various parameters needed for orchestration, such as the executable ID and scenario ID.
โข To start, install the dependency in your project.
npm install @sap-ai-sdk/ai-apiโข Add the following code to your project to create an orchestration configuration:
import { ConfigurationApi } from '@sap-ai-sdk/ai-api';
const RESOURCE_GROUP = 'YourResourceGroupId'; // Please change to your desired resource group
// Create orchestration configuration using ConfigurationApi
async function createOrchestrationConfiguration() {
try {
const response = await ConfigurationApi
.configurationCreate({
name: 'orchestration-config', // Choose a meaningful name
executableId: 'orchestration', // Orchestration executable ID
scenarioId: 'orchestration', // Orchestration scenario ID
}, {'AI-Resource-Group': RESOURCE_GROUP}).execute();
return response;
} catch (error: any) {
// Handle API errors
console.error('Configuration creation failed:', error.stack);
}
}
const configuration = await createOrchestrationConfiguration();
console.log(configuration?.message); // Print the configuration response message
In this step, we will create a deployment from the configuration created in the previous step using the @sap-ai-sdk/ai-api package of the SAP Cloud SDK for AI (JavaScript). For more information, refer to the official documentation.
โข Add the following code to your project to create an orchestration deployment:
import { DeploymentApi } from '@sap-ai-sdk/ai-api';
import type { AiDeploymentCreationResponse } from '@sap-ai-sdk/ai-api';
// Create Orchestration deployment using DeploymentApi
async function createOrchestrationDeployment() {
โฏ // Extract the configuration ID from the result of the previous step
const configurationId = configuration.id;
โฏ try {
โฏ โฏ const response = await DeploymentApi
.deploymentCreate(
{ configurationId },
{ 'AI-Resource-Group': RESOURCE_GROUP }
).execute();
return response;
โฏ } catch (error: any) {
console.error('Deployment creation failed:', error.stack);
โฏ }
}
const deployment = await createOrchestrationDeployment();
console.log(deployment?.message) // Print the deployment creation response
In this step, we will create an orchestration configuration using the core module of the SAP Cloud SDK for AI (Java). This configuration integrates various parameters needed for orchestration, such as the executable ID and scenario ID.
โข Add the following code to your project to create an orchestration configuration:
// Define the resource group, change this to your resource group name
var RESOURCE_GROUP = "yourResourceGroup";
// Define parameter and input artifact bindings you may need for orchestration
var modelFilterList = AiParameterArgumentBinding.create()
.key("modelFilterList").value("null");
var modelFilterListType = AiParameterArgumentBinding.create()
.key("modelFilterListType").value("allow");
// Create a configuration data object for your configuration
var configurationData = AiConfigurationBaseData.create()
.name("orchestration-config") // Choose a meaningful name
.executableId("orchestration") // Orchestration executable ID
.scenarioId("orchestration") // Orchestration scenario ID
.addParameterBindingsItem(modelFilterList)
.addParameterBindingsItem(modelFilterListType);
// Create the configuration with your individual resource group
var configuration = new ConfigurationApi().create(RESOURCE_GROUP, configurationData);
// Print the configuration response message
System.out.println(configuration.getMessage());Note:
โข scenarioId and executableId: Both are set to “orchestration” for this tutorial.
โข name: Choose a unique name for the configuration (e.g., “config-new-orchestration”)
In this step, we will create a deployment from the configuration created in the previous step using the core module of the SAP Cloud SDK for AI (Java).
โข Add the following code to your project to create an orchestration deployment:
// Create a deployment creation request with the ID of the created configuration
var deploymentCreationRequest =
AiDeploymentCreationRequest.create().configurationId(configuration.getId());
// Create the deployment with the deployment creation request
var deployment = new DeploymentApi().create(RESOURCE_GROUP, deploymentCreationRequest);
// Print the deployment response message
System.out.println(deployment.getMessage());Create Resource Group
Expand the 01_resource_group section in the collection.
Click on the create request and execute it to create a resource group.

img Next, execute the get_by_id request to verify the resource group status.
- Ensure the status is PROVISIONED.
Follow the screenshot attached for reference.

img
Create Configuration
Navigate to the configuration request and execute it to create a configuration.
Copy the ID from the response for use in subsequent steps.
Follow the screenshot attached for reference.

img Navigate to the create_deployment request.
Update the Configuration ID in the request body with the ID obtained in the previous step.
Execute the request to create a deployment. Follow the screenshot attached for reference.

img
Verify Deployment Status
- Execute the get_deployment request repeatedly until:
- The status is RUNNING.
- The deploymentUrl appears in the response.
Follow the screenshot attached for reference.
Update Environment Variable
Copy the deploymentUrl from the response.
Paste it into the orchestration_service_url field of the Grounding-test environment.
Save the updated environment. Follow the screenshot attached for reference.

img
Please note that the model and model-version referenced in the tutorial may differ from the current offerings. Refer to the SAP Note for the list of available models.
โข Navigate to the resource group where your orchestration has been deployed.
โข Go to Generative AI Hub.
โข Select Orchestration and click on Templating.
โข In the Templating section, locate the message icon with three tabs: User, Assistance, and System.
Please take note that the screenshots in tutorial may slightly vary from the current AILaunchpad UI.
Click on the User tab, Enter the following details:
Prompt:
Here is a candidate's resume: {{ ?candidate_resume }} Variable Definitions:
โข The variable โcandidate_resumeโ will be created.
โข Enter the default values according to your use case. For this example, use the following resume information (you can copy-paste this text):
John Doe
1234 Data St, San Francisco, CA 94101
(123) 456-7890
johndoe@email.com
LinkedIn Profile
GitHub Profile
Objective
Detail-oriented Data Scientist with 3+ years of experience in data analysis, statistical modeling, and machine learning. Seeking to leverage expertise in predictive modeling and data visualization to help drive data-informed decision-making at [Company Name].
Education
Master of Science in Data Science
University of California, Berkeley
Graduated: May 2021
Bachelor of Science in Computer Science
University of California, Los Angeles
Graduated: May 2019
Technical Skills
Programming Languages: Python, R, SQL, Java
Data Analysis & Visualization: Pandas, NumPy, Matplotlib, Seaborn, Tableau
Machine Learning: Scikit-learn, TensorFlow, Keras, XGBoost
Big Data Technologies: Hadoop, Spark
Databases: MySQL, PostgreSQL
Version Control: Git
Professional Experience
Data Scientist
DataCorp Inc., San Francisco, CA
June 2021 โ Present
Developed predictive models to optimize marketing campaigns, which increased ROI by 20%.
Conducted in-depth data analysis using Python and SQL to identify trends and patterns in large datasets.
Collaborated with cross-functional teams to implement data-driven strategies that improved customer satisfaction scores by 15%.
Created interactive dashboards using Tableau to visualize KPIs for stakeholders.
Data Analyst Intern
Analytics Solutions, Los Angeles, CA
June 2020 โ August 2020
Analyzed large datasets to identify opportunities for business growth and improvement.
Assisted in the development of automated reporting tools using Python and Excel.
Worked with data visualization tools to create insightful reports for management.
Projects
Customer Segmentation Analysis
Conducted K-means clustering on customer data to segment the customer base into distinct groups, enabling targeted marketing strategies.
Predictive Stock Price Modeling
Built a predictive model using time series analysis to forecast stock prices, achieving an accuracy rate of 85%.
Sentiment Analysis on Social Media
Implemented natural language processing techniques to analyze sentiment from tweets, providing insights into public opinion on various topics.
Certifications
Certified Data Scientist (CDS) โ Data Science Council of America
Machine Learning Specialization โ Coursera by Stanford University
Professional Affiliations
Member, Association for Computing Machinery (ACM)
Member, Data Science Society
References
Available upon request.
Personal Interests
- I absolutely love exploring new technologies and working on innovative projects.
- I enjoy reading books, especially on artificial intelligence and machine learning.
- I hate people who are dishonest and unreliable.
- I love traveling and experiencing new cultures.
- I enjoy playing video games, especially competitive ones.
- I hate being stuck in a routine; I always seek new challenges and growth opportunities.
- I hate working in xyz cloud -"xyz cloud is the most irritating platform i have ever used"

โข After entering the details, click on Add.
โข A new message box will appear. Proceed to configure the System tab. enter the following details:
Prompt:
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. 
Data masking and input content filtering are optional advanced modules. In this tutorial, our primary focus is on consumption. Please set the values as shown in the screenshots below.


โข Navigate to the Model Configuration section.
โข Select your Deployment ID and choose the model you want to use for this orchestration.


Output content filtering is an optional advanced module. In this tutorial, our focus is on consumption. Please configure it as shown in the screenshots below.

After configuring model settings, click on the Test icon and run the orchestration.
Check the Result section for the response.

Important Note
Ensure at least one orchestration deployment is ready to be consumed during this process.
Optional Advanced Modules
Data masking and content filtering are available to enhance data privacy and safety. Data masking hides sensitive information like phone numbers or organization names, while content filtering can screen for categories such as hate self-harm, sexual content, and violence. In this tutorial, the response generated by the LLM models may carry sensitive information, such as names and phone numbers. For further enhancement, refer to the next tutorial on implementing these modules.
To begin the consumption process for the orchestration youโve deployed, follow the process below:
Prepare the CV File
Download the cv.txt file, which contains the CV data that will be used in this use case.
Place the cv.txt file in the same folder where you have created your .ipynb file.
Load the CV file using the following code to read its content
from gen_ai_hub.orchestration.utils import load_text_file
# Load the CV file content
cv_file_path = "cv.txt" โฏ# Specify the correct path to the CV file
cv_content = load_text_file(cv_file_path)
# Print the content to verify it has been loaded
print(cv_content) The next step involves creating a template that specifies how the AI should handle the resume content. The template will include both SystemMessage and UserMessage components.
โข SystemMessage: Defines the AI assistant’s role and instructions.
โข UserMessage: Represents the user’s input (i.e., the CV content) to be processed by the AI.
from gen_ai_hub.orchestration.models.message import SystemMessage, UserMessage
from gen_ai_hub.orchestration.models.template import Template, TemplateValue
# Define the template for resume screening
template = Template(
โฏ โฏ messages=[
โฏ โฏ โฏ โฏ SystemMessage("""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"""),
โฏ โฏ โฏ โฏ UserMessage(
โฏ โฏ โฏ โฏ โฏ โฏ "Here is a candidate's resume: {{ ?candidate_resume }}"
โฏ โฏ โฏ โฏ ),
โฏ โฏ ],
โฏ โฏ defaults=[
โฏ โฏ โฏ โฏ TemplateValue(name="candidate_resume", value="John Doe's resume content goes here..."),
โฏ โฏ ],
) Hereโs an example of how to configure them:
from gen_ai_hub.orchestration.models.llm import LLM
from gen_ai_hub.orchestration.models.config import OrchestrationConfig
# List of models to use
models = [
โฏ โฏ LLM(name="gpt-4o", version="latest", parameters={"max_tokens": 1000, "temperature": 0.6}),
โฏ โฏ LLM(name="mistralai--mistral-large-instruct", version="latest", parameters={"max_tokens": 1000, "temperature": 0.6}),
โฏ โฏ LLM(name="anthropic--claude-3-sonnet", version="latest", parameters={"max_tokens": 1000, "temperature": 0.6}),
]
# Create configurations for each model
configs = []
for model in models:
โฏ โฏ # Create orchestration config for each model
โฏ โฏ config = OrchestrationConfig(
โฏ โฏ โฏ โฏ template=template, โฏ
โฏ โฏ โฏ โฏ llm=model, โฏ
โฏ โฏ )
โฏ โฏ configs.append(config)
print("Model configurations created successfully:") Execute the Orchestration and Collect Results
Now, you can run the orchestration with the prepared configurations. The results will be saved in a text file for later review.
from gen_ai_hub.orchestration.service import OrchestrationService
# Initialize an empty list to store the responses
responses = []
# Iterate through each config and get the response using the filtered input
for i, config in enumerate(configs):
โฏ โฏ orchestration_service = OrchestrationService(api_url=ready_deployment.deployment_url, config=config)
โฏ โฏ # Run orchestration with the provided input (for example, candidate resume content)
โฏ โฏ result = orchestration_service.run(template_values=[
โฏ โฏ โฏ โฏ TemplateValue(name="candidate_resume", value=cv_content) โฏ# Adjust 'cv_content' as needed
โฏ โฏ ])
โฏ โฏ # Extract the response content
โฏ โฏ response = result.orchestration_result.choices[0].message.content
โฏ โฏ # Append the response to the responses list
โฏ โฏ responses.append({
โฏ โฏ โฏ โฏ "model": models[i].name, โฏ# Store model name
โฏ โฏ โฏ โฏ "response": response โฏ โฏ โฏ# Store the corresponding model response
โฏ โฏ })
# Store the responses in a text file
with open("model_responses.txt", "w") as file:
โฏ โฏ for response_data in responses:
โฏ โฏ โฏ โฏ file.write(f"Response from model {response_data['model']}:\n")
โฏ โฏ โฏ โฏ file.write(f"{response_data['response']}\n")
โฏ โฏ โฏ โฏ file.write("-" * 80 + "\n") โฏ# Add a separator between model responses After running the orchestration, a model_responses.txt file will be generated in the same folder. This file will contain the responses from all the models you used, each separated by a line for clarity.
Important Note
Ensure at least one orchestration deployment is ready to be consumed during this process.
Optional Advanced Modules
Data masking and content filtering are available to enhance data privacy and safety. Data masking hides sensitive information like phone numbers or organization names, while content filtering can screen for categories such as hate self-harm, sexual content, and violence. In this tutorial, the response generated by the LLM models may carry sensitive information, such as names and phone numbers. For further enhancement, refer to the next tutorial on implementing these modules.
In this step, we will consume the orchestration service using the @sap-ai-sdk/orchestration package of the SAP Cloud SDK for AI (JavaScript). For more information, refer to the official documentation.
Prepare the CV File
Download the cv.txt file, which contains the CV data used in this tutorial.
Place the cv.txt file in the current working directory.
Load the CV file using the following code to read its content
import { readFile } from 'node:fs/promises';
const cvContent = await readFile('path/to/cv.txt', 'utf-8');The next step involves creating a template that specifies how the AI should handle the CV content. The template will include message components with different roles:
โข system: Defines the AI assistant’s role and instructions.
โข user: Represents the user’s input to be processed.
import type { PromptTemplate } from '@sap-ai-sdk/orchestration';
// Define the system and user messages
const promptTemplate: PromptTemplate = {
template: [
{
role: 'system',
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.',
},
{
role: 'user',
content: 'Candidate Resume:\n{{ ?candidate_resume }}',
},
],
};
We will use multiple models for this tutorial. Since orchestration provides direct access to models without requiring separate deployments, you can use any available models. For this example, we have selected the following models:
// List of models to iterate through
const models = [
'gpt-4o',
'mistralai--mistral-large-instruct',
'anthropic--claude-3.5-sonnet',
];
Generate Responses for Multiple Models
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.
Key Points:
Model Iteration: Asynchronously iterates over the list of model names to update the LLM configuration dynamically.
Query Execution: Uses OrchestrationClient to generate responses for each query.
import { writeFile } from 'node:fs/promises';
import { OrchestrationClient } from '@sap-ai-sdk/orchestration';
// Generate responses from multiple models using OrchestrationClient
async function generateResponsesForModels(cvContent: string) {
// Initialize OrchestrationClient asynchronously for list of models
const responses = await Promise.all(
models.map(async (model) => {
const orchestrationClient = new OrchestrationClient(
{
promptTemplating: {
prompt: promptTemplate,
model: {
name: model,
params: {
max_tokens: 1000,
temperature: 0.6,
},
},
}
},
{ resourceGroup: RESOURCE_GROUP }
);
try {
// Run orchestration with the provided input (candidate resume content)
const response = await orchestrationClient.chatCompletion({
placeholderValues: { candidate_resume: cvContent },
});
// Extract the response content and return it
return {
model,
response: response.getContent(),
};
} catch (error: any) {
console.error(`Error with model ${model}:`, error.stack);
}
})
);
// Optionally save the responses to a file
await writeFile(
'model_responses_js.txt',
responses
.map((res) => `Response from model ${res.model}:\n${res.response}\n${'-'.repeat(80)}\n`)
.join(''),
'utf-8'
);
return responses;
}
// Example usage
const modelResponses = await generateResponsesForModels(cvContent);
modelResponses.map(response => {
console.log(`==== Response with Model: ${response.model} ====\n${response.response || 'No response available'}\n`);
});Important Note
Ensure at least one orchestration deployment is ready to be consumed during this process.
Optional Advanced Modules
Data masking and content filtering are available to enhance data privacy and safety. Data masking hides sensitive information like phone numbers or organization names, while content filtering can screen for categories such as hate self-harm, sexual content, and violence. In this tutorial, the response generated by the LLM models may carry sensitive information, such as names and phone numbers. For further enhancement, refer to the next tutorial on implementing these modules.
Grounding is available to integrate external, contextually relevant, domain-specific, or real-time data into your workflows.
For more information about the orchestration module configurations, refer to the official documentation.
In this step, we will consume an LLM through the orchestration service with the created deployment, using the core and orchestration module of the SAP Cloud SDK for AI (Java).
To begin the consumption process, follow the steps below:
Prepare the CV File
โข Download the cv.txt file, which contains the CV used this tutorial. Add it to your project.
โข Read the CV file from the correct path using the following code:
// Adapt filepath to the location you stored the file
var filePath = "path/to/cv.txt";
// Read file into string
String cvContent;
try {
cvContent = new String(Files.readAllBytes(Paths.get(filePath)));
} catch (IOException e) {
throw new RuntimeException(e);
}
// Print file content
System.out.println(cvContent);The next step involves creating the prompt for the LLM including both SystemMessage and UserMessage components.
โข SystemMessage: Defines the AI assistant’s role and instructions.
โข UserMessage: Represents the user’s input (i.e., the CV content) to be processed by the LLM.
// Define system and user messages for prompt
var systemMessage = Message.system(
"""
You are a helpful AI assistant for HR. Summarize the following CV in 10 sentences,
using on key qualifications, work experience, and achievements. Include personal contact information,
organizational history, and personal interests.
"""
);
var userMessage = Message.user("Candidate Resume: \n" + cvContent);
// Define the prompt for resume screening
var prompt = new OrchestrationPrompt(systemMessage, userMessage);We can define model parameters and a list of models to use. Only use those models that are already deployed in your instances. For this example, we have selected the following parameters and models:
// List of models with parameters to iterate through, can be adapted if desired
var models = Stream.of(
OrchestrationAiModel.GPT_4O,
OrchestrationAiModel.MISTRAL_LARGE_INSTRUCT,
OrchestrationAiModel.CLAUDE_3_5_SONNET
).map(model -> model.withParam(MAX_TOKENS, 1000).withParam(TEMPERATURE, 0.6)).toList();The following function writes the responses from different models, stored in a list, to a file:
// Function writing responses to a file
void createFileFromResponses (ArrayList<Map> responses) {
// Format model responses
var formattedResponses = responses.stream().
map(response -> "Response from model " + response.get("model") +
": \n\n" + response.get("response"));
// Write model responses to provided file path
try {
Files.writeString(Path.of("provided/path/to/responses.txt"),
String.join("\n\n" + "-".repeat(120) + "\n\n", formattedResponses.toList()));
} catch (IOException e) {
throw new RuntimeException(e);
}
}Generate Responses for Multiple Models
This step outlines the process of generating responses for a set of queries using different models. We iterate through the list of models created earlier and query the model with the created prompt using an OrchestrationClient.
// Create the client used for interaction with orchestration service
var client = new OrchestrationClient(new AiCoreService()
.getInferenceDestination(RESOURCE_GROUP).forScenario("orchestration"));
// Create orchestration module configuration
var moduleConfig = new OrchestrationModuleConfig();
// A list to store all responses from the different models
var responses = new ArrayList<Map>();
// Iterate through the list of models
for (var model: models) {
System.out.println("\n=== Responses for model: %s ===\n".formatted(model.getName()));
// Prompt LLM with specific LLM config for model
var response = client.chatCompletion(prompt, moduleConfig.withLlmConfig(model));
// Add response to list of all model responses
responses.add(Map.of("model", model.getName(), "response", response.getContent()));
System.out.println(response.getContent());
}
// Write all responses to a file
createFileFromResponses(responses);Important Note
Ensure at least one orchestration deployment is ready to be consumed during this process.
Optional Advanced Modules
Together with document grounding and templating, data masking and content filtering are available to enhance data privacy and safety. Data masking hides sensitive information like phone numbers or organization names, while content filtering can screen for categories such as hate self-harm, sexual content, and violence. In this tutorial, the response generated by the LLM models may carry sensitive information, such as names and phone numbers. For further enhancement, refer to the next tutorial on implementing these modules.
Go to the 08_consume_model section in the collection.
Select the direct_model_usage request for consuming the deployed model.
Expand the Body section of the request. Replace the current JSON in the Body with the following updated JSON
{
"orchestration_config": {
"module_configurations": {
"llm_module_config": {
"model_name": "gpt-4o",
"model_params": {},
"model_version": "2024-05-13"
},
"templating_module_config": {
"template": [
{
"role": "system",
"content": "You are an AI assistant designed to screen resumes for HR purposes. Please assess the candidate qualifications based on the provided resume."
},
{
"role": "user",
"content": "Candidate Resume:\n{{ ?candidate_resume }}"
}
],
"defaults": {
"candidate_resume": "John Doe\n1234 Data St, San Francisco, CA 94101\n(123) 456-7890\njohndoe@email.com\nLinkedIn Profile\nGitHub Profile\n\nObjective\nDetail-oriented Data Scientist with 3+ years of experience in data analysis, statistical modeling, and machine learning. Seeking to leverage expertise in predictive modeling and data visualization to help drive data-informed decision-making at [Company Name].\n\nEducation\nMaster of Science in Data Science\nUniversity of California, Berkeley\nGraduated: May 2021\n\nBachelor of Science in Computer Science\nUniversity of California, Los Angeles\nGraduated: May 2019\n\nTechnical Skills\n\nProgramming Languages: Python, R, SQL, Java\nData Analysis & Visualization: Pandas, NumPy, Matplotlib, Seaborn, Tableau\nMachine Learning: Scikit-learn, TensorFlow, Keras, XGBoost\nBig Data Technologies: Hadoop, Spark\nDatabases: MySQL, PostgreSQL\nVersion Control: Git\n\nProfessional Experience\n\nData Scientist\nDataCorp Inc., San Francisco, CA\nJune 2021 โ Present\n\nDeveloped predictive models to optimize marketing campaigns, which increased ROI by 20%.\nConducted in-depth data analysis using Python and SQL to identify trends and patterns in large datasets.\nCollaborated with cross-functional teams to implement data-driven strategies that improved customer satisfaction scores by 15%.\nCreated interactive dashboards using Tableau to visualize KPIs for stakeholders.\n\nData Analyst Intern\nAnalytics Solutions, Los Angeles, CA\nJune 2020 โ August 2020\n\nAnalyzed large datasets to identify opportunities for business growth and improvement.\nAssisted in the development of automated reporting tools using Python and Excel.\nWorked with data visualization tools to create insightful reports for management.\n\nProjects\n\nCustomer Segmentation Analysis\nConducted K-means clustering on customer data to segment the customer base into distinct groups, enabling targeted marketing strategies.\n\nPredictive Stock Price Modeling\nBuilt a predictive model using time series analysis to forecast stock prices, achieving an accuracy rate of 85%.\n\nSentiment Analysis on Social Media\nImplemented natural language processing techniques to analyze sentiment from tweets, providing insights into public opinion on various topics.\n\nCertifications\n\nCertified Data Scientist (CDS) โ Data Science Council of America\nMachine Learning Specialization โ Coursera by Stanford University\n\nProfessional Affiliations\n\nMember, Association for Computing Machinery (ACM)\nMember, Data Science Society\n\nReferences\nAvailable upon request.\n\nPersonal Interests\n- I absolutely love exploring new technologies and working on innovative projects.\n- I enjoy reading books, especially on artificial intelligence and machine learning.\n- I hate people who are dishonest and unreliable."
}
}
}
}
}In the request body, specify the model name that you want to consume.
Ensure the input parameters are formatted as per the model’s requirements. Follow the screenshot attached for reference.
Click on Send to execute the request.
Review the response to see the output from the model. Follow the screenshot attached for reference.

img
Optional Advanced Modules
Data masking and content filtering are available to enhance data privacy and safety. Data masking hides sensitive information like phone numbers or organization names, while content filtering can screen for categories such as hate self-harm, sexual content, and violence. In this tutorial, the response generated by the LLM models may carry sensitive information, such as names and phone numbers etc.. For further enhancement, refer to the next tutorial on implementing these modules.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.