You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- description --> In this tutorial we are going to learn on how to deploy a custom LLM on AI core using ollama for the example we would be taking Gemma as a model from hugging face and deploy it on SAP AI core.
10
+
# Using Small Language models on SAP AI Core VIA ollama
11
+
<!-- description --> In this tutorial we are going to learn on how to deploy a SLM on AI core using ollama for the example we would be taking llava-phi3 as a model from hugging face and deploy it on SAP AI core
12
12
13
13
## You will learn
14
14
- How to Deploy ollama on AI core
15
-
- Add models to ollama and infrence models
15
+
- Add models to ollama and inference models
16
16
17
17
## Prerequisites
18
18
Ai core setup and basic knowledge: [Link to documentation](https://developers.sap.com/tutorials/ai-core-setup.html)
@@ -25,7 +25,7 @@ In this tutorial we are deploying ollama an open-source project that serves as a
25
25
26
26

27
27
28
-
We can pick any model from the above model hubs and connect it to AI core for the example we are going to deploy ollama on AI core and enable Gemma and inference the same.
28
+
We can pick any model from the above model hubs and connect it to AI core for the example we are going to deploy ollama on AI core and enable llava-phi3 and inference the same.
29
29
30
30
### Adding workflow file to github
31
31
Workflows for SAP AI Core are created using YAML or JSON files that are compatible with the SAP AI Core schema. Let’s start with adding a Argo Workflow file to manage: `ollama`.
- Here, we extend the use case introduced in Previous Tutorial, where orchestration was executed without incorporating data masking or content filtering. Here, we will include these advanced modules to improve data privacy, security, and response quality.
112
112
113
-
**NOTE** : If you are continuing with the same project from the previous tutorial, skip steps 1 and 2. Otherwise, create a new Java Maven project using the already deployed orchestration URL to access the Harmonized API. Please find detailed information on orchestration configuration and deployment in the previous tutorial or our [GitHub repository](https://github.com/SAP/ai-sdk-java).
113
+
**NOTE** : If you are continuing with the same project from the previous tutorial, skip steps 1 and 2. Otherwise, create a new Java Maven project using the already deployed orchestration URL to access the Harmonized API. Please find detailed information on orchestration configuration and deployment in the previous tutorial or in our [documentation](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java).
• For other options of access configuration and detailed information on installation and usage of the **SAP Cloud SDK for AI (for Java)**, visit the official [GitHub repository](https://github.com/SAP/ai-sdk-java). This page provides comprehensive steps to set up and integrate the SDK effectively in your projects.
105
+
• 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](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java). This page provides comprehensive steps to set up and integrate the SDK effectively in your projects.
In this step, we will create an orchestration configuration using the core module of the [SAP Cloud SDK for Java](https://github.com/SAP/cloud-sdk-java). This configuration integrates various parameters needed for orchestration, such as the executable ID and scenario ID.
274
+
In this step, we will create an orchestration configuration using the core module of the [SAP Cloud SDK for AI (Java)](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java). This configuration integrates various parameters needed for orchestration, such as the executable ID and scenario ID.
275
275
276
276
• Add the following code to your project to create an orchestration configuration:
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 Java](https://github.com/SAP/cloud-sdk-java).
445
+
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)](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java).
446
446
447
447
• Add the following code to your project to create an orchestration deployment:
448
448
@@ -915,7 +915,7 @@ Ensure at least one orchestration deployment is ready to be consumed during this
915
915
916
916
[OPTION BEGIN [Java SDK]]
917
917
918
-
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 Java](https://github.com/SAP/cloud-sdk-java).
918
+
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)](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java).
919
919
920
920
To begin the consumption process, follow the steps below:
Copy file name to clipboardExpand all lines: tutorials/ai-core-orchestration-grounding/ai-core-orchestration-Grounding.md
+258-9Lines changed: 258 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,15 @@ To interact with SAP AI Core using **SAP Cloud SDK for AI (for JavaScript)**, yo
41
41
42
42
[OPTION END]
43
43
44
-
[OPTION BEGIN [Gen AI SDK]]
44
+
[OPTION BEGIN [Java SDK]]
45
45
46
-
To interact with SAP AI Core using Gen AI SDK, you first need to create a service key that grants secure access to your AI Core instance. Follow the step Set Up Your Environment and Configure Access in the [tutorial] (https://developers.sap.com/tutorials/ai-core-orchestration-consumption.html) to establish your connection.
46
+
To interact with SAP AI Core using the [Java SDK](https://sap.github.io/ai-sdk/docs/java/overview-cloud-sdk-for-ai-java), you first need to create a service key that grants secure access to your AI Core instance. Follow the step Set Up Your Environment and Configure Access in the [tutorial](https://developers.sap.com/tutorials/ai-core-orchestration-consumption.html) to establish your connection.
47
+
48
+
[OPTION END]
49
+
50
+
[OPTION BEGIN [Python SDK]]
51
+
52
+
To interact with SAP AI Core using the python Gen AI SDK, you first need to create a service key that grants secure access to your AI Core instance. Follow the step Set Up Your Environment and Configure Access in the [tutorial](https://developers.sap.com/tutorials/ai-core-orchestration-consumption.html) to establish your connection.
47
53
48
54
[OPTION END]
49
55
@@ -111,7 +117,13 @@ The JavaScript SDK automatically retrieves the AI Core service credentials and r
111
117
112
118
[OPTION END]
113
119
114
-
[OPTION BEGIN [Gen AI SDK]]
120
+
[OPTION BEGIN [Java SDK]]
121
+
122
+
As the access token is automatically initially requested and sent with every request to the server, this step is not necessary for the Java SDK.
123
+
124
+
[OPTION END]
125
+
126
+
[OPTION BEGIN [Python SDK]]
115
127
116
128
This step generates an access token, required for authenticating API requests during the process.
117
129
@@ -240,7 +252,32 @@ console.log("Created Resource Group with ID: ", resourceGroup?.resourceGroupId)
240
252
241
253
[OPTION END]
242
254
243
-
[OPTION BEGIN [Gen AI SDK]]
255
+
[OPTION BEGIN [Java SDK]]
256
+
257
+
Create a resource group in SAP AI Core. Please note that for using the document grounding service, your request must contain the document grounding label set to true. Therefore, existing resource groups without the label won't work.
258
+
259
+
```java
260
+
// Your resource group ID, please change to your desired ID
261
+
varRESOURCE_GROUP="YourResourceGroupId";
262
+
263
+
// Request to create the resource group
264
+
var resourceGroupRequest =BckndResourceGroupsPostRequest.create()
265
+
.resourceGroupId(RESOURCE_GROUP)
266
+
.addLabelsItem(BckndResourceGroupLabel.create()
267
+
.key("ext.ai.sap.com/document-grounding")
268
+
.value("true")
269
+
);
270
+
271
+
// Create resource group
272
+
var resourceGroup =newResourceGroupApi().create(resourceGroupRequest);
273
+
274
+
System.out.println("Created Resource Group with ID: "+resourceGroup.getResourceGroupId());
275
+
276
+
```
277
+
278
+
[OPTION END]
279
+
280
+
[OPTION BEGIN [Python SDK]]
244
281
245
282
Create a resource group in SAP AI Core by defining its ID and quota, ensuring efficient resource allocation for AI workloads.
246
283
@@ -412,7 +449,43 @@ console.log(secret?.message)
412
449
413
450
[OPTION END]
414
451
415
-
[OPTION BEGIN [Gen AI SDK]]
452
+
[OPTION BEGIN [Java SDK]]
453
+
454
+
Generic secrets securely store SharePoint credentials required for document access. Please change the values to your SharePoint credentials.
455
+
456
+
```java
457
+
// Request to create the secret
458
+
var secretRequest =BckndGenericSecretPostBody.create()
459
+
.name("canary-rg1-secret")
460
+
.data(Map.ofEntries(
461
+
Map.entry("type", "SFRUUA=="),
462
+
Map.entry("description", "<description of generic secret>"),
463
+
Map.entry("clientId", "<client id>"),
464
+
Map.entry("authentication", "<AUTHENTICATION>"),
465
+
Map.entry("tokenServiceUrl", "<token service url>"),
466
+
Map.entry("password", "<password>"),
467
+
Map.entry("proxyType", "<PROXY>"),
468
+
Map.entry("url", "<URL>"),
469
+
Map.entry("tokenServiceURLType", "<TOKEN SERVICE URL TYPE>"),
470
+
Map.entry("user", "<user>"),
471
+
Map.entry("clientSecret", "<clientSecret>"),
472
+
Map.entry("scope", "<SCOPE>")
473
+
))
474
+
.addLabelsItem(BckndGenericSecretLabel.create()
475
+
.key("ext.ai.sap.com/document-grounding")
476
+
.value("true")
477
+
);
478
+
479
+
// Create secret
480
+
var secret =newSecretApi().create(secretRequest);
481
+
482
+
System.out.println(secret.getMessage());
483
+
484
+
```
485
+
486
+
[OPTION END]
487
+
488
+
[OPTION BEGIN [Python SDK]]
416
489
417
490
Generic secrets securely store SharePoint credentials required for document access
418
491
@@ -456,12 +529,12 @@ secret.json()
456
529
457
530
[OPTION END]
458
531
459
-
### 7. Prepare knowledge base(data repository) and verification
460
-
461
-
#### 7.a Using Pipeline API [Option-1]
532
+
### 7. Prepare knowledge base (data repository) and verification
462
533
463
534
[OPTION BEGIN [Bruno]]
464
535
536
+
### 7.a Using Pipeline API
537
+
465
538
#### Create Pipeline
466
539
467
540
- Pipelines define the process for grounding and retrieving content from SharePoint repositories.
@@ -647,6 +720,131 @@ These steps help inspect vector collections and documents to confirm successful
647
720
648
721
[OPTION END]
649
722
723
+
[OPTION BEGIN [JavaScript SDK]]
724
+
725
+
we are creating a document-grounding pipeline using SAP AI Core. The pipeline is configured to integrate with Microsoft SharePoint as a data source, enabling AI-driven document processing. This setup allows seamless ingestion of documents from a specified SharePoint site, ensuring efficient data retrieval and processing.
726
+
727
+
**Note:** At present, pipeline creation is not supported in the grounding feature of Cloud SDK, as we have utilized API requests to establish the pipeline.
728
+
729
+
```javascript
730
+
731
+
const jsonData = {
732
+
type: 'MSSharePoint',
733
+
configuration: {
734
+
destination: '<generic secret name>',
735
+
sharePoint: {
736
+
site: {
737
+
name: '<sharepoint site name>',
738
+
includePaths: [
739
+
"/<folder name>"
740
+
]
741
+
}
742
+
}
743
+
}
744
+
};
745
+
746
+
const headers = {
747
+
"Authorization": `Bearer ${token}`, // Use your actual token
748
+
"Content-Type": "application/json",
749
+
"AI-Resource-Group": "default" // Replace with your resource group
We are creating a document-grounding pipeline using SAP AI Core. The pipeline is configured to integrate with Microsoft SharePoint as a data source, enabling AI-driven document processing. This setup allows seamless ingestion of documents from a specified SharePoint site, ensuring efficient data retrieval and processing.
783
+
784
+
**Note:** For this step, we are using the [document grounding module](https://sap.github.io/ai-sdk/docs/java/guides/document-grounding) of the SDK so make sure to add the dependency to your project.
var pipeline = new GroundingClient().pipelines().createPipeline(
802
+
RESOURCE_GROUP,
803
+
pipelineRequest
804
+
);
805
+
806
+
System.out.println("Created Pipeline with ID: " + pipeline.getPipelineId());
807
+
808
+
```
809
+
810
+
[OPTION END]
811
+
812
+
[OPTION BEGIN [Python SDK]]
813
+
814
+
we are creating a document-grounding pipeline using SAP AI Core. The pipeline is configured to integrate with Microsoft SharePoint as a data source, enabling AI-driven document processing. This setup allows seamless ingestion of documents from a specified SharePoint site, ensuring efficient data retrieval and processing.
815
+
816
+
**Note:** At present, pipeline creation is not supported in the grounding feature of Gen AI SDK, as we have utilized API requests to establish the pipeline.
In the previous steps, we have completed the data preparation for grounding. Before initiating model inference or orchestration, ensure that there is an active orchestration deployment (**scenario ID: orchestration**). To verify the available orchestration deployments and their status, use the **get_deployment** API under the **"Deployments"** section in the **Bruno collection**. Additionally, update the **orchestration_service_url** in the environment.
We are configuring an AI Orchestration Pipeline using SAP AI Core. The pipeline integrates multiple AI modules to process and refine inputs efficiently. This setup enables **document grounding, LLM processing, templating, and content filtering**, ensuring accurate and safe AI-generated responses.
1015
+
1016
+
The configuration defines a document grounding module that retrieves relevant context from a vector-based repository, a GPT-4o model for response generation, a templating module to structure responses, and Azure Content Safety filters to ensure compliance and content moderation. This orchestration streamlines AI-driven summarization while maintaining reliability and security.
1017
+
1018
+
```java
1019
+
// Create a database filter used for the grounding configuration
1020
+
var dataBaseFilter = DocumentGroundingFilter.create()
1021
+
.dataRepositoryType(DataRepositoryType.VECTOR)
1022
+
.id("filter1")
1023
+
.addDataRepositoriesItem("23c**********************5ed6") //Replace with the value of your data repository ID
// Create a grounding configuration with the database filter
1027
+
var groundingConfig = Grounding.create()
1028
+
.filters(dataBaseFilter);
1029
+
1030
+
// Create a grounding prompt which will combine the provided user message with the grounding output
1031
+
var groundingPrompt = groundingConfig.createGroundingPrompt("Is there any complaint?");
1032
+
1033
+
// Create an input content filter
1034
+
var inputFilter = new AzureContentFilter()
1035
+
.hate(ALLOW_SAFE_LOW)
1036
+
.selfHarm(ALLOW_SAFE_LOW)
1037
+
.sexual(ALLOW_SAFE_LOW)
1038
+
.violence(ALLOW_SAFE_LOW);
1039
+
1040
+
// Create an output content filter
1041
+
var outputFilter = new AzureContentFilter()
1042
+
.hate(ALLOW_SAFE_LOW)
1043
+
.selfHarm(ALLOW_SAFE_LOW)
1044
+
.sexual(ALLOW_SAFE_LOW)
1045
+
.violence(ALLOW_SAFE_LOW);
1046
+
1047
+
// Create an orchestration module config for the model gpt-4o with grounding and filtering
1048
+
var orchestrationModuleConfig = new OrchestrationModuleConfig()
1049
+
.withLlmConfig(OrchestrationAiModel.GPT_4O)
1050
+
.withGrounding(groundingConfig)
1051
+
.withInputFiltering(inputFilter)
1052
+
.withOutputFiltering(outputFilter);
1053
+
1054
+
// Prompt LLM with created grounding prompt and orchestration module configuration
1055
+
var response = client.chatCompletion(groundingPrompt, orchestrationModuleConfig);
1056
+
1057
+
System.out.println(response.getContent());
1058
+
1059
+
```
1060
+
1061
+
[OPTION END]
1062
+
1063
+
[OPTION BEGIN [Python SDK]]
815
1064
816
1065
We are configuring an AI Orchestration Pipeline using SAP AI Core. The pipeline integrates multiple AI modules to process and refine inputs efficiently. This setup enables **document grounding, LLM processing, templating, and content filtering**, ensuring accurate and safe AI-generated responses.
0 commit comments