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

feat: Prompt registry follow up #594

Merged
merged 8 commits into from
Mar 18, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/deep-ends-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ai-sdk/prompt-registry': minor
---

[New Functionality] Add a new package `@sap-ai-sdk/prompt-registry` for consuming APIs from prompt registry service.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Setup your SAP AI Core instance with SAP Cloud SDK for AI.
- [@sap-ai-sdk/foundation-models](#sap-ai-sdkfoundation-models)
- [@sap-ai-sdk/langchain](#sap-ai-sdklangchain)
- [@sap-ai-sdk/orchestration](#sap-ai-sdkorchestration)
- [@sap-ai-sdk/document-grounding](#sap-ai-sdkdocument-grounding)
- [@sap-ai-sdk/prompt-registry](#sap-ai-sdkprompt-registry)
- [SAP Cloud SDK for AI Sample Project](#sap-cloud-sdk-for-ai-sample-project)
- [Error Handling](#error-handling)
Expand Down Expand Up @@ -91,6 +92,21 @@ $ npm install @sap-ai-sdk/orchestration

For details on orchestration client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/orchestration/README.md).

### @sap-ai-sdk/document-grounding

> [!warning]
> This package is still in **beta** and is subject to breaking changes. Use it with caution.

This package incorporates generative AI document grounding [Pipeline API](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/pipeline-api-a9badce6a4da4df68e98549d64aa2217), [Vector API](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/vector-api-0358c5ca839d4cf7b4982dbcbc1ba7ff) and [Retrieval API](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/retrieval-api) into your AI activities in SAP AI Core and SAP AI Launchpad.

#### Installation

```
$ npm install @sap-ai-sdk/document-grounding
```

For details on document grounding client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/document-grounding/README.md).

### @sap-ai-sdk/prompt-registry

This package incorporates generative AI [prompt registry](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/prompt-registry) into your AI activities in SAP AI Core and SAP AI Launchpad.
Expand Down
8 changes: 5 additions & 3 deletions packages/prompt-registry/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
> [!warning]
> This package is still in **beta** and is subject to breaking changes. Use it with caution.

# @sap-ai-sdk/prompt-registry

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.
Expand All @@ -14,6 +11,7 @@ This package incorporates generative AI prompt registry capabilities into your A
- [Usage](#usage)
- [List Prompt Templates](#list-prompt-templates)
- [Custom Destination](#custom-destination)
- [Error Handling](#error-handling)
- [Local Testing](#local-testing)
- [Support, Feedback, Contribution](#support-feedback-contribution)
- [License](#license)
Expand Down Expand Up @@ -65,6 +63,10 @@ const response: PromptTemplateListResponse =
});
```

## Error Handling

For error handling instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#error-handling).

## Local Testing

For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).
Expand Down
17 changes: 13 additions & 4 deletions sample-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Parts of the sample code are also used in E2E tests.
- [AI API](#ai-api)
- [Foundation Models (Azure OpenAI)](#foundation-models-azure-openai)
- [Orchestration](#orchestration)
- [Langchain](#langchain)
- [LangChain](#langchain)
- [Document Grounding](#document-grounding)
- [Prompt Registry](#prompt-registry)

## Local Deployment

Expand Down Expand Up @@ -261,7 +262,7 @@ The chain performs RAG with the chat and embedding client.

#### E2E flow for Orchestration Grounding using `vector` as the Data Repository

`GET /document-grounding/invoke-orchestration-grounding-vector`
`GET /document-grounding/orchestration-grounding-vector`

This scenario demonstrates the end-to-end flow for creating collections and documents using the document grounding service, and then using the orchestration grounding module to get a chat completion response with a retrieved context based on `vector` data repository.

Expand All @@ -275,7 +276,7 @@ The created collection will be deleted at the end of the flow.

#### E2E flow for Retrieving Documents

`GET /document-grounding/invoke-retrieve-documents`
`GET /document-grounding/retrieve-documents`

This scenario demonstrates the end-to-end flow for creating collections and documents using the document grounding service, and then retrieving the documents with a query.

Expand All @@ -285,11 +286,19 @@ The created collection will be deleted at the end of the flow.

#### E2E flow for Orchestration Grounding using `help.sap.com` as the Data Repository

`GET /document-grounding/invoke-orchestration-grounding-help-sap-com`
`GET /document-grounding/orchestration-grounding-help-sap-com`

This scenario uses the orchestration grounding module to get a chat completion response with a retrieved context based on `help.sap.com` data repository.

Orchestration service will send a chat completion request with the context to LLM.
The response should contain the same timestamp.

The created collection will be deleted at the end of the flow.

### Prompt Registry

#### Create and Delete Prompt Template

`GET /prompt-registry/template`

Create a prompt template and delete it.
5 changes: 5 additions & 0 deletions sample-code/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ export {
createDocumentsWithTimestamp,
deleteCollection
} from './document-grounding.js';

export {
createPromptTemplate,
deletePromptTemplate
} from './prompt-registry.js';
13 changes: 5 additions & 8 deletions sample-code/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ app.get('/langchain/invoke-tool-chain', async (req, res) => {

/* Document Grounding */
app.get(
'/document-grounding/invoke-orchestration-grounding-vector',
'/document-grounding/orchestration-grounding-vector',
async (req, res) => {
try {
res.setHeader('Content-Type', 'text/event-stream');
Expand Down Expand Up @@ -449,7 +449,7 @@ app.get(
}
);

app.get('/document-grounding/invoke-retrieve-documents', async (req, res) => {
app.get('/document-grounding/retrieve-documents', async (req, res) => {
try {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Connection', 'keep-alive');
Expand Down Expand Up @@ -501,7 +501,7 @@ app.get('/document-grounding/invoke-retrieve-documents', async (req, res) => {
});

app.get(
'/document-grounding/invoke-orchestration-grounding-help-sap-com',
'/document-grounding/orchestration-grounding-help-sap-com',
async (req, res) => {
try {
const groundingResult = await orchestrationGroundingHelpSapCom();
Expand All @@ -514,7 +514,7 @@ app.get(
}
);

app.get('/prompt-registry/invoke', async (req, res) => {
app.get('/prompt-registry/template', async (req, res) => {
try {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Connection', 'keep-alive');
Expand All @@ -531,9 +531,6 @@ app.get('/prompt-registry/invoke', async (req, res) => {

res.end();
} catch (error: any) {
console.error(error);
res
.status(500)
.send('Yikes, vibes are off apparently 😬 -> ' + error.message);
sendError(res, error);
}
});
20 changes: 20 additions & 0 deletions tests/e2e-tests/src/prompt-registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
createPromptTemplate,
deletePromptTemplate
} from '@sap-ai-sdk/sample-code';
import { loadEnv } from './utils/load-env.js';

loadEnv();

describe('prompt registry', () => {
it('should create a prompt template and then delete', async () => {
const { id } = await createPromptTemplate(
'ai-sdk-js-e2e-test',
'orchestration'
);
expect(id.length).toEqual(36);

const { message } = await deletePromptTemplate(id);
expect(message).toEqual('Prompt deleted successfully.');
});
});
Loading