diff --git a/tutorials/ai-core-genaihub-prompt-registry/ai-core-genaihub-prompt-registry.md b/tutorials/ai-core-genaihub-prompt-registry/ai-core-genaihub-prompt-registry.md index 840721a53..973bbc0f3 100644 --- a/tutorials/ai-core-genaihub-prompt-registry/ai-core-genaihub-prompt-registry.md +++ b/tutorials/ai-core-genaihub-prompt-registry/ai-core-genaihub-prompt-registry.md @@ -33,10 +33,13 @@ A **Prompt Registry** is a centralized system for storing, managing, and version **Why Use a Prompt Registry?** -• **Consistency** – Ensures uniform prompts across different use cases. -• **Version Control** – Tracks prompt iterations and allows rollback if needed. -• **Collaboration** – Enables teams to work on prompt engineering collaboratively. -• **Automation** – Integrates prompts seamlessly into AI workflows and CI/CD pipelines. +- **Consistency** – Ensures uniform prompts across different use cases. + +- **Version Control** – Tracks prompt iterations and allows rollback if needed. + +- **Collaboration** – Enables teams to work on prompt engineering collaboratively. + +- **Automation** – Integrates prompts seamlessly into AI workflows and CI/CD pipelines. There are two key approaches to managing prompts in a **Prompt Registry**: @@ -53,27 +56,24 @@ Next, let's dive into the Declarative approach to creating a prompt template. - The declarative approach allows you to manage prompt templates using Git repositories, ensuring automatic synchronization with the Prompt Registry. Instead of making API calls to create and update templates manually, you define them in YAML files, commit them to Git, and let the system handle synchronization. -- Create a prompt template and push it to your git repository. The file must be named in the following format: “.prompttemplate.ai.sap.yaml”. +- Create a prompt template and push it to your git repository. The file must be named in the following format: “**your-template-name**.prompttemplate.ai.sap.yaml”. - YAML File Structure: Copy the below code ```YAML -name: simple -version: 0.0.1 -scenario: my-scenario +name: multi_task +version: 1.1.1 +scenario: multi-task-processing spec: template: - role: "system" content: "{{ ?instruction }}" - role: "user" content: "Take {{ ?user_input }} from here" - - role: "assistant" - content: "Output received: {{ ?grounding_output_variable }}" defaults: instruction: "default instruction" user_input: "default user input" - grounding_output_variable: "default output" additionalFields: isDev: true validations: @@ -86,10 +86,13 @@ spec: ``` ![img](img/image001.png) + **Note** - The defaults and additionalFields fields are optional. The additionalFields field is unstructured and can be used to store metadata or configuration objects. Refer to the screenshot above for reference. - Once the YAML file is created and pushed to Git, the system automatically syncs it with the Prompt Registry. +[OPTION END] + ### Onboarding Github and Application on AI core [OPTION BEGIN [AI Launchpad]] @@ -100,15 +103,26 @@ spec: **Note:** If you don’t see the AI Core Administration app, check that you had selected your SAP AI Core connection from the Workspaces app. If it is still not visible then ask your SAP AI Launchpad administrator to assign roles to you so that you can access the app. -- Enter your GitHub repository details (created in the previous step) in the dialog box that appears, and click **Add**. +![img](img/img_1.png) +**Enter your GitHub Repository Details** Use the following information as reference: -- **URL**: Paste the URL of your GitHub repository and add the suffix /workflows. +- **URL**: Paste the URL of your GitHub repository. + - Example: **https://github.tools.sap/your-username/your-repository** + - **Username**: Your GitHub username. -- **Password**: Paste your GitHub Personal Access Token + - Example: **johndoe** + +- **Password**: Paste your GitHub Personal Access Token, Follow below steps to create the Access Token -![img](img/image005.png) +![img](img/img_2.png) +![img](img/img_3.png) +![img](img/img_4.png) +![img](img/img_5.png) +![img](img/img_6.png) +![img](img/img_7.png) +![img](img/img_8.png) **Note:** Password does not gets validated at time of Adding Github Repository its just meant to save Github Creds to AI core. Passwords gets validated at time of creating Application or when Application refreshes connection to AI core. @@ -124,7 +138,7 @@ You will see your GitHub onboarding completed in a few seconds. As a next steps - **Application Name**: An identifier of your choice. - **Repository URL**: Your GitHub account URL and repository suffix. This helps you select the credentials to access the repository. - **Path**: The folder in your GitHub where your workflow is located. For this tutorial it is LearningScenarios. - - **Revision**: The is the unique ID of your GitHub commit. Set this to HEAD to have it automatically refer to the latest commit. + - **Revision**: The is the unique ID of your GitHub commit. Set this to **HEAD** to have it automatically refer to the latest commit. **Click on the application you created, then select 'Sync' to synchronize your changes.** ![img](img/image009.png) @@ -141,33 +155,196 @@ After synchronization, navigate to **ML Operations > Scenarios** in the **SAP AI Once the template is synced to the **AI Core Launchpad**, follow these steps to integrate it into your orchestration: -- Navigate to Generative AI Hub and select the Template tab. -![img](img/image026.png) +- Navigate to Generative AI Hub and select the Edit Workflow option. Then, disable the Grounding module. -- Choose your desired template and click Select. The Templating section will update accordingly. ![img](img/image027.png) -- Go to the Grounding section and set the input variable to user_input and In the Data Repositories section, click the + icon and select the required pipeline. +- Click on the Template tab, click on the Select icon, and choose your synced template from the list. + ![img](img/image028.png) - Configure Data Masking by selecting the sensitive information categories (e.g., Name, Organization) that need to be masked. sensitive information. + ![img](img/image029.png) - Set Input Filtering thresholds for content moderation categories such as Hate, Self-Harm, Sexual, and Violence. Adjust the settings to Allow Safe and Low / Block Medium and High as needed. + ![img](img/image030.png) - Select Model Configuration by choosing the appropriate model for orchestration. + ![img](img/image031.png) - Set Output Filtering using the same threshold settings as input filtering to ensure consistency in moderated responses. + ![img](img/image032.png) - Once all configurations are complete, click Test to validate your orchestration workflow. - - Instruction: "Provide a brief explanation of SAP AI Core and its key functionalities." - - User Input: "What are the main capabilities of SAP AI Core?" + - Instruction: "Provide a brief explanation of SAP AI Core and its key functionalities." + - User Input: "What are the main capabilities of SAP AI Core?" - After entering these values, execute the test to verify the response. The system should return relevant details based on your configured prompt template and filtering settings. ![img](img/image033.png) [OPTION END] +### Prompt Templates for Different Use Cases and Reusability + +[OPTION BEGIN [AI Launchpad]] + +**In Step 4**, we experimented with a single prompt. Now, let's explore some predefined prompt templates designed for various tasks. + +To proceed: +- **Go to the Git repository** and edit the YAML file. + +- Keep only the following three fields **constant** in the YAML file: + + -**name** + + -**version** (Ensure you increment the version, e.g., from 1.1.1 to 1.1.2 when making updates.) + + -**scenario** + +- **Copy and paste** the relevant prompt templates from below into the YAML files. Modify only the **spec** section of the **YAML** file while keeping other sections unchanged. + +![img](img/image034.png) +- **Save the file and sync** it to the application. + +**NOTE:**- Please refer to Step 4 for details on modifying the YAML file in Git, syncing it with the application, and ensuring the changes are reflected correctly. + +- **Test the different tasks** using these templates to see how they adapt to different use cases. + +**Note:** This section provides reusable prompt templates designed for various use cases in SAP AI Launchpad. Each template follows a structured format to ensure consistent and accurate outputs. Below are the prompt templates for different NLP tasks. + +#### The Prompt Template Resource + +**Template for Text Expansion** + +```YAML +spec: + template: + - role: "system" + content: | + Expand the following short text into a detailed explanation. + Return output as: + Expanded Text: {{ expanded_output }} + - role: "user" + content: "Text: {{ ?short_text }}" + additionalFields: + isDev: true + validations: + required: true +``` +**Template for Multi-Task Processing** +```YAML +spec: + template: + - role: "system" + content: | + Perform multiple tasks at once: Detect language and translate to English. + Respond in the following format: + Language: + Converted to English: + - role: "user" + content: "Text: {{ ?input_text }}" + additionalFields: + isDev: true + validations: + required: true +``` + +**Template for Spell Check and Correction** + +```YAML +spec: + template: + - role: "system" + content: "Correct any spelling and grammatical errors in the given text. Corrected Text: {{ corrected_output }}" + - role: "user" + content: "{{ ?input_text }}" + defaults: + input_text: "default input text" + + additionalFields: + isDev: true + validations: + required: true +``` + +**Template for Sentiment Analysis** + +```YAML +spec: + template: + - role: "system" + content: | + Classify the sentiment of the given text. + Respond in the following format: + Sentiment: {{ classification_output }} + - role: "user" + content: "Text: {{ ?input_text }}" + additionalFields: + isDev: true + validations: + required: true +``` + +**Template for Text Summarization** + +```YAML +spec: + template: + - role: "system" + content: | + Summarize the following text. + Respond in the following format: + Summary: {{ summary_output }} + - role: "user" + content: "Text: {{ ?input_text }}" + additionalFields: + isDev: true + validations: + required: true +``` + +**Template for Tone Adjustment** + +```YAML +spec: + template: + - role: "system" + content: | + Translate the following input to a Corporate language. + Respond in the following format: + Corporate Version: {{ corporate_output }} + - role: "user" + content: "Text: {{ ?input_text }}" + additionalFields: + isDev: true + validations: + required: true +``` + +**Template for Question Answering** + +```YAML +spec: + template: + - role: "system" + content: | + Answer the question based on the given context. + Respond in the following format: + Answer: {{ answer_output }} + - role: "user" + content: | + Context: {{ ?context }} + Question: {{ ?question }} + additionalFields: + isDev: true + validations: + required: true +``` +**NOTE:** If required, you can create a new YAML file for different tasks instead of modifying the existing one. This helps maintain clarity and version control. + +[OPTION END] + diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/image001.png b/tutorials/ai-core-genaihub-prompt-registry/img/image001.png index 650e1a167..97fb216fd 100644 Binary files a/tutorials/ai-core-genaihub-prompt-registry/img/image001.png and b/tutorials/ai-core-genaihub-prompt-registry/img/image001.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/image027.png b/tutorials/ai-core-genaihub-prompt-registry/img/image027.png index 3a050ca95..3442a8c11 100644 Binary files a/tutorials/ai-core-genaihub-prompt-registry/img/image027.png and b/tutorials/ai-core-genaihub-prompt-registry/img/image027.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/image028.png b/tutorials/ai-core-genaihub-prompt-registry/img/image028.png index 459ef22da..0d6f8a57c 100644 Binary files a/tutorials/ai-core-genaihub-prompt-registry/img/image028.png and b/tutorials/ai-core-genaihub-prompt-registry/img/image028.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/image034.png b/tutorials/ai-core-genaihub-prompt-registry/img/image034.png new file mode 100644 index 000000000..22c12452c Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/image034.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_1.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_1.png new file mode 100644 index 000000000..752501e18 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_1.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_10.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_10.png new file mode 100644 index 000000000..c1bd14144 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_10.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_2.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_2.png new file mode 100644 index 000000000..d4c5e896b Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_2.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_3.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_3.png new file mode 100644 index 000000000..6b12227cd Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_3.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_4.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_4.png new file mode 100644 index 000000000..08641f2c6 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_4.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_5.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_5.png new file mode 100644 index 000000000..c02ab4ed2 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_5.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_6.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_6.png new file mode 100644 index 000000000..97b588906 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_6.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_7.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_7.png new file mode 100644 index 000000000..d9f81eb22 Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_7.png differ diff --git a/tutorials/ai-core-genaihub-prompt-registry/img/img_8.png b/tutorials/ai-core-genaihub-prompt-registry/img/img_8.png new file mode 100644 index 000000000..1ff3a447a Binary files /dev/null and b/tutorials/ai-core-genaihub-prompt-registry/img/img_8.png differ diff --git a/tutorials/ai-core-orchestration-grounding/ai-core-orchestration-Grounding.md b/tutorials/ai-core-orchestration-grounding/ai-core-orchestration-Grounding.md index 97ae10a34..95bf2e85d 100644 --- a/tutorials/ai-core-orchestration-grounding/ai-core-orchestration-Grounding.md +++ b/tutorials/ai-core-orchestration-grounding/ai-core-orchestration-Grounding.md @@ -22,7 +22,7 @@ author_profile: https://github.com/I321506 - [How to create a BTP Account (internal)](https://me.sap.com/notes/3493139) - [SAP AI Core Documentation](https://help.sap.com/docs/sap-ai-core?version=INTERNAL&locale=en-US&state=PRODUCTION) - AI Core setup and basic knowledge: [Link to documentation](https://developers.sap.com/tutorials/ai-core-setup.html). -- An AI Core instance with a Standard Plan or Extended Plan. +- An AI Core instance with Extended Plan. - Access to Microsoft SharePoint for grounding capabilities. ### 1. Create service key for AI Core instance @@ -33,29 +33,8 @@ This step enables the foundational setup of the AI Core instance by creating a s • You can follow steps in https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/enabling-service-in-cloud-foundry?locale=en-US to create an AI Core instance and service key in development environment -[OPTION END] - -[OPTION BEGIN [JavaScript SDK]] - -To interact with SAP AI Core using **SAP Cloud SDK for AI (for JavaScript)**, 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. - -[OPTION END] -[OPTION BEGIN [Java SDK]] - -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. - -[OPTION END] - -[OPTION BEGIN [Python SDK]] - -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. - -[OPTION END] - -### 2. Download and import Bruno collection - -[OPTION BEGIN [Bruno]] +#### Download and import Bruno collection This step prepares the workspace by importing pre-configured requests for easy interaction with AI Core services using Bruno collections. @@ -69,11 +48,7 @@ This step prepares the workspace by importing pre-configured requests for easy i ![img](img/image003.png) -[OPTION END] - -### 3. Set env variables - -[OPTION BEGIN [Bruno]] +#### Set env variables Environment variables centralize configuration settings required for seamless integration between your service key and the imported collection. @@ -101,7 +76,49 @@ Environment variables centralize configuration settings required for seamless in [OPTION END] -### 4. Generate token +[OPTION BEGIN [JavaScript SDK]] + +To interact with SAP AI Core using SAP Cloud 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. + +```javascript + +import dotenv from "dotenv"; +dotenv.config(); + +const serviceKey = JSON.parse(process.env.AICORE_SERVICE_KEY); + +const AI_API_URL = serviceKey.serviceurls.AI_API_URL; +const clientid = serviceKey.clientid; +const clientsecret = serviceKey.clientsecret; +const authUrl = serviceKey.url; + +console.log("AI API URL:", AI_API_URL); + +``` +[OPTION END] + +[OPTION BEGIN [Java SDK]] + +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. + +[OPTION END] + +[OPTION BEGIN [Python SDK]] + +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. + +• Configure proxy modules by setting up environment variables for AI Core credentials. + +• Replace placeholder values in ~/.aicore/config.json with AI Core service keys from BTP. + +• Optionally, set the AICORE_HOME environment variable to override the default config path. + + +![img](img/image077.png) + +[OPTION END] + +### 2. Generate token [OPTION BEGIN [Bruno]] @@ -157,7 +174,7 @@ print(token) [OPTION END] -### 5. Create resource group +### 3. Create resource group [OPTION BEGIN [Bruno]] @@ -307,10 +324,12 @@ resource.json() [OPTION END] -### 6. Create generic secret +### 4. Create generic secret [OPTION BEGIN [Bruno]] +#### **Generic secret for sharepoint (option-1)** + Generic secrets securely store SharePoint credentials required for document access • Expand **03_generic_secret** and select create request @@ -329,6 +348,49 @@ Generic secrets securely store SharePoint credentials required for document acce • All values needs to be provided as base 64 encoded values +#### **Generic secret for AWS S3 (option-2)** + +Generic secrets securely store AWS S3 credentials required for document access + +• Expand **03_generic_secret** and select create request + +Use the below payload to create a secret for AWS S3 with NoAuthentication as authentication type. + +```CODE + +{ + "name": "", // Name of the generic secret to be created + "data": { + "url": "", // Base64 encoded value of url + "authentication": "Tm9BdXRoZW50aWNhdGlvbg=", // Base64 encoded value for NoAuthentication + "description": "", // Base64 encoded description of the secret + "access_key_id": "", // Base64 encoded value of access key id + "bucket": "", // Base64 encoded value of bucket name + "host": "", // Base64 encoded value of host + "region": "", // Base64 encoded value of region + "secret_access_key": "", // Base64 encoded value of secret access key + "username": "", // Base64 encoded value of username + "type": "SFRUUA==", // [Optional] Base64 encoded value for HTTP + "proxyType": "SW50ZXJuZXQ=", // [Optional] Base64 encoded value for Internet + }, + "labels": [ + { + "key": "ext.ai.sap.com/document-grounding", // Label for Document Grounding feature + "value": "true" + }, + { + "key": "ext.ai.sap.com/documentRepositoryType", // Label for Document Repository Type + "value": "S3" + } + ] +} + +``` + +•Ensure that all values in the data dictionary are Base64-encoded as per AWS S3 credential requirements. + +![img](img/image072.png) + [OPTION END] [OPTION BEGIN [AI Launchpad]] @@ -489,7 +551,7 @@ System.out.println(secret.getMessage()); Generic secrets securely store SharePoint credentials required for document access -```python +```Python headers = { 'AI-Resource-Group': resource.json()['resourceGroupId'], @@ -529,17 +591,19 @@ secret.json() [OPTION END] -### 7. Prepare knowledge base (data repository) and verification - -[OPTION BEGIN [Bruno]] +### 5. Prepare knowledge base (data repository) and verification -### 7.a Using Pipeline API +[OPTION BEGIN [Bruno]] +#### 5.a Using Pipeline API [Option-1] + #### Create Pipeline -- Pipelines define the process for grounding and retrieving content from SharePoint repositories. +- Pipelines define the process for grounding and retrieving content from SharePoint and AWS S3 repositories. -In this use case, we have added facility management emails as grounding documents, uploading them to the designated SharePoint folder. I’m attaching the sample email folder [sample_emails] (img/sample_emails) used in this scenario. For practice, you can also use these emails if needed. +In this use case, we have added facility management emails as grounding documents, uploading them to the designated SharePoint folder. I’m attaching the sample email folder [sample_emails.zip] (img/sample_emails.zip) used in this scenario. For practice, you can also use these emails if needed. + +#### **Pipeline for MSSharePoint (Option-1)** • **Expand 04_pipeline** and select **create_pipeline** request @@ -551,114 +615,89 @@ In this use case, we have added facility management emails as grounding document ![img](img/image014.png) -#### Get All Pipelines +#### **Pipeline for AWS S3 (Option-2)** -This request retrieves a list of all existing pipelines within the resource group. It helps in managing and monitoring available pipelines for orchestration. +**Download and install AWS CLI from the AWS CLI official page.** -![img](img/image031.png) +Open Command Prompt and configure AWS CLI with your credentials: -#### Get Pipeline by Pipeline ID +Enter your Access Key, Secret Key, Region, and Output Format when prompted. -This request fetches details of a specific pipeline using its unique ID. It is useful for verifying the configuration and settings of a particular pipeline. +```COPY -![img](img/image032.png) +aws configure -#### Get Pipeline Status by Pipeline ID +``` +![img](img/image074.png) -This request checks the current status of a specific pipeline, such as whether it is running, completed, or failed. It helps in tracking the execution progress. +**Upload a Grounding Document to AWS S3** -![img](img/image033.png) - -Once the pipeline is successfully created, documents uploaded in SharePoint are converted into vectors via APIs. The conversion process can be validated upon successful pipeline execution. +To upload a grounding document to an S3 bucket, use: -[OPTION END] +```CODE -[OPTION BEGIN [JavaScript SDK]] +aws s3 cp s3://// -In this step, we will create a document-grounding pipeline in SAP AI Core using the `@sap-ai-sdk/document-grounding` package of the [SAP Cloud SDK for AI (JavaScript)](https://github.com/SAP/ai-sdk-js/tree/main/packages/document-grounding). +``` -• To start, install the dependency to your project. +**Verify File Upload** + +To check if the file is uploaded successfully, list the contents of the folder: + +```CODE + +aws s3 ls s3://// ``` -npm install @sap-ai-sdk/document-grounding -``` +![img](img/image076.png) -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. +**Create an AWS S3 Pipeline** +**Expand 04_pipeline** and select **create_pipeline** request -```javascript +Use the below payload to create a pipeline for AWS S3. -import { PipelinesApi } from '@sap-ai-sdk/document-grounding'; +```CODE -async function createPipeline() { - try { - const response = await PipelinesApi.createPipeline({ - type: 'MSSharePoint', - configuration: { - destination: '', - sharePoint: { - site: { - name: '', - includePaths: [ - '/' - ] - } - } - } - }, - { 'AI-Resource-Group': RESOURCE_GROUP }).execute(); - return response; - } catch (error: any) { - console.error('Error while creating Resource Group:', error.stack); - } +{ + "type": "S3", + "configuration": { + "destination": "" // Name of the generic secret created for S3 + }, + "metadata": { // [Optional] + "destination": "", // Name of the generic secret created for S3 MetaData Server + } } -const pipeline = await createPipeline(); -console.log('Created Pipeline with ID:', pipeline?.pipelineId); - ``` +• Replace value **generic_secret_name** with generic secret name created in step 8. -[OPTION END] +**Note:**'metadata' is an optional field which takes the destination name created for the s3 metadata server. -[OPTION BEGIN [Gen AI SDK]] +![img](img/image069.png) -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. +#### Get All Pipelines -**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. +This request retrieves a list of all existing pipelines within the resource group. It helps in managing and monitoring available pipelines for orchestration. -```python +![img](img/image031.png) -json_data = { - 'type': 'MSSharePoint', - 'configuration': { - 'destination': '', - 'sharePoint': { - 'site': { - 'name': '', - "includePaths": [ - "/" - ] - }, - }, - }, -} +#### Get Pipeline by Pipeline ID -while True: - pipeline = requests.post(f'{AI_API_URL}/v2/lm/document-grounding/pipelines', headers=headers, json=json_data) - if(pipeline.status_code == 201): - break +This request fetches details of a specific pipeline using its unique ID. It is useful for verifying the configuration and settings of a particular pipeline. -pipeline.json()['pipelineId'] +![img](img/image032.png) -``` +#### Get Pipeline Status by Pipeline ID -![img](img/image063.png) +This request checks the current status of a specific pipeline, such as whether it is running, completed, or failed. It helps in tracking the execution progress. -[OPTION END] +![img](img/image033.png) + +Once the pipeline is successfully created, documents uploaded in SharePoint are converted into vectors via APIs. The conversion process can be validated upon successful pipeline execution. -#### 7.b Using Vector API [Option-2] -[OPTION BEGIN [Bruno]] +#### 5.b Using Vector API [Option-2] #### Create collection @@ -845,7 +884,7 @@ pipeline.json()['pipelineId'] [OPTION END] -### 8. Ensuring Accurate Responses with Grounding +### 6. Ensuring Accurate Responses with Grounding 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. @@ -1060,99 +1099,78 @@ System.out.println(response.getContent()); [OPTION END] -[OPTION BEGIN [Python SDK]] +[OPTION BEGIN [ Python SDK]] 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. 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. -```python - -#JSON from Docuemnt grounding API -json_data = { - "orchestration_config": { - "module_configurations": { - "grounding_module_config": { - "type": "document_grounding_service", - "config": { - "filters": [ - { - "id": "filter1", - "data_repositories": [ - "23c9*********************55ed6" // Replace the value with your data repository ID - ], - "search_config": { - "max_chunk_count": 10 - }, - "data_repository_type": "vector" - } - ], - "input_params": [ - "groundingRequest" - ], - "output_param": "groundingOutput" - } - }, - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": {}, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "You are a precise and reliable assistant. Using only the provided context, generate a concise and accurate summary relevant to the request. Do not infer or generate information beyond the given context. If the requested information is not available in the context, clearly state that. Request: {{ ?groundingRequest }} Context: {{ ?groundingOutput }}" - } - ], - "defaults": {} - }, - "filtering_module_config": { - "input": { - "filters": [ - { - "type": "azure_content_safety", - "config": { - "Hate": 2, - "SelfHarm": 2, - "Sexual": 2, - "Violence": 2 - } - } - ] - }, - "output": { - "filters": [ - { - "type": "azure_content_safety", - "config": { - "Hate": 2, - "SelfHarm": 2, - "Sexual": 2, - "Violence": 2 - } - } - ] - } - } +``` python + +# Import libraries +from gen_ai_hub.proxy import get_proxy_client +from gen_ai_hub.orchestration.models.config import OrchestrationConfig +from gen_ai_hub.orchestration.models.document_grounding import (GroundingModule, DocumentGrounding, GroundingFilterSearch,DataRepositoryType, DocumentGroundingFilter) +from gen_ai_hub.orchestration.models.llm import LLM +from gen_ai_hub.orchestration.models.message import SystemMessage, UserMessage +from gen_ai_hub.orchestration.models.template import Template, TemplateValue +from gen_ai_hub.orchestration.service import OrchestrationService + +orchestration_service_url = "https://api.**********.hana.ondemand.com/v2/inference/deployments/d6**********98" + +# Set up the Orchestration Service +aicore_client = get_proxy_client().ai_core_client +orchestration_service = OrchestrationService(api_url=orchestration_service_url) +llm = LLM( + name="gpt-4o", + parameters={ + 'temperature': 0.0, } - }, - "input_params": { - "groundingRequest": "Is there any complaint?" - } -} +) +template = Template( + messages=[ + SystemMessage("""Facility Solutions Company provides services to luxury residential complexes, apartments, + individual homes, and commercial properties such as office buildings, retail spaces, industrial facilities, and educational institutions. + Customers are encouraged to reach out with maintenance requests, service deficiencies, follow-ups, or any issues they need by email. + """), + UserMessage("""You are a helpful assistant for any queries for answering questions. + Answer the request by providing relevant answers that fit to the request. + Request: {{ ?user_query }} + Context:{{ ?grounding_response }} + """), + ] + ) -deploymentUrl = "https://api.ai.prodeuonly.***************************************fb3" -orchestration = requests.post(f'{deploymentUrl}/completion', headers=headers, json=json_data) #call the orchestration completion api +# Set up Document Grounding +filters = [DocumentGroundingFilter(id="vector", + data_repositories=["69*************f9"], # Replace with data repository ID + search_config=GroundingFilterSearch(max_chunk_count=15), + data_repository_type=DataRepositoryType.VECTOR.value + ) +] + +grounding_config = GroundingModule( + type="document_grounding_service", + config=DocumentGrounding(input_params=["user_query"], output_param="grounding_response", filters=filters) + ) -# Get the response JSON -if orchestration.status_code == 200: - result = orchestration.json() # Parse JSON response - print(result) -else: - print(f"Error: {orchestration.status_code}, {orchestration.text}") +config = OrchestrationConfig( + template=template, + llm=llm, + grounding=grounding_config +) + +response = orchestration_service.run(config=config, + template_values=[ + TemplateValue("user_query", "Is there any complaint?"), + ]) +print(response.orchestration_result.choices[0].message.content) ``` +**Sample Response 1:** +![img](img/image070.png) + +**Sample Response 2:** ![img](img/image064.png) @@ -1162,7 +1180,7 @@ else: ### Conclusion -**Adding Grounding significantly enhances the model's ability to provide Accurate and Context-specific responses. Without Grounding, the model generates generic replies, while with grounding, it retrieves precise information from the uploaded document. Screenshots showcasing both responses are provided for comparison.** +Adding Grounding significantly enhances the model's ability to provide Accurate and Context-specific responses. Without Grounding, the model generates generic replies, while with grounding, it retrieves precise information from the uploaded document. Screenshots showcasing both responses are provided for comparison. diff --git a/tutorials/ai-core-orchestration-grounding/img/image069.png b/tutorials/ai-core-orchestration-grounding/img/image069.png new file mode 100644 index 000000000..0784c664d Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image069.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image070.png b/tutorials/ai-core-orchestration-grounding/img/image070.png new file mode 100644 index 000000000..2d5dcc5bb Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image070.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image072.png b/tutorials/ai-core-orchestration-grounding/img/image072.png new file mode 100644 index 000000000..f9905d8a8 Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image072.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image074.png b/tutorials/ai-core-orchestration-grounding/img/image074.png new file mode 100644 index 000000000..fdb8279cb Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image074.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image075.png b/tutorials/ai-core-orchestration-grounding/img/image075.png new file mode 100644 index 000000000..669e02d0a Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image075.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image076.png b/tutorials/ai-core-orchestration-grounding/img/image076.png new file mode 100644 index 000000000..930dea1df Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image076.png differ diff --git a/tutorials/ai-core-orchestration-grounding/img/image077.png b/tutorials/ai-core-orchestration-grounding/img/image077.png new file mode 100644 index 000000000..74e16191c Binary files /dev/null and b/tutorials/ai-core-orchestration-grounding/img/image077.png differ