Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt registry and grounding document tutorials #23897

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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**:

Expand All @@ -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: “<template-name>.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:
Expand All @@ -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]]
Expand All @@ -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.

Expand All @@ -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)
Expand All @@ -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: <detected_language>
Converted to English: <translated_text>
- 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]

Binary file modified tutorials/ai-core-genaihub-prompt-registry/img/image001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/ai-core-genaihub-prompt-registry/img/image027.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tutorials/ai-core-genaihub-prompt-registry/img/image028.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading