Skip to content

Commit 9dbce25

Browse files
ZhongpinWangcloud-sdk-jsdeekshas8
authored
feat: Add prompt registry client (#551)
* feat: add the first version of prompt registry * refactor: change from defaultApi into seperate apis * fix: lock * fix: lock * fix: package json * chore: add tests for prompt templates api * fix: Changes from lint * chore: add sample code for prompt registry service * docs: add readme * fix: typo * fix:lint * docs: add prompt registry to root README * remove internal and health endpoints * add beta warning --------- Co-authored-by: cloud-sdk-js <[email protected]> Co-authored-by: deeksha sinha <[email protected]>
1 parent 6f28f47 commit 9dbce25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1576
-13
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Setup your SAP AI Core instance with SAP Cloud SDK for AI.
1717
- [@sap-ai-sdk/foundation-models](#sap-ai-sdkfoundation-models)
1818
- [@sap-ai-sdk/langchain](#sap-ai-sdklangchain)
1919
- [@sap-ai-sdk/orchestration](#sap-ai-sdkorchestration)
20+
- [@sap-ai-sdk/prompt-registry](#sap-ai-sdkprompt-registry)
2021
- [SAP Cloud SDK for AI Sample Project](#sap-cloud-sdk-for-ai-sample-project)
2122
- [Error Handling](#error-handling)
2223
- [Accessing Error Information](#accessing-error-information)
@@ -90,6 +91,18 @@ $ npm install @sap-ai-sdk/orchestration
9091

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

94+
### @sap-ai-sdk/prompt-registry
95+
96+
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.
97+
98+
#### Installation
99+
100+
```
101+
$ npm install @sap-ai-sdk/prompt-registry
102+
```
103+
104+
For details on prompt registry client, refer to this [document](https://github.com/SAP/ai-sdk-js/blob/main/packages/prompt-registry/README.md).
105+
93106
## SAP Cloud SDK for AI Sample Project
94107

95108
We have created a sample project demonstrating the different clients' usage of the SAP Cloud SDK for AI for TypeScript/JavaScript.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"core": "pnpm -F=@sap-ai-sdk/core",
2626
"document-grounding": "pnpm -F=@sap-ai-sdk/document-grounding",
2727
"langchain": "pnpm -F=@sap-ai-sdk/langchain",
28+
"prompt-registry": "pnpm -F=@sap-ai-sdk/prompt-registry",
2829
"e2e-tests": "pnpm -F=@sap-ai-sdk/e2e-tests",
2930
"type-tests": "pnpm -F=@sap-ai-sdk/type-tests",
3031
"smoke-tests": "pnpm -F=@sap-ai-sdk/smoke-tests",

packages/document-grounding/README.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,18 @@ In addition to the examples below, you can find more **sample code** [here](http
5151
### Create a Collection
5252

5353
```ts
54-
import
55-
const response =
56-
await VectorApi.createCollection(
57-
{
58-
title: 'ai-sdk-js-e2e',
59-
embeddingConfig: {
60-
modelName: 'text-embedding-ada-002'
61-
},
62-
metadata: []
54+
const response = await VectorApi.createCollection(
55+
{
56+
title: 'ai-sdk-js-e2e',
57+
embeddingConfig: {
58+
modelName: 'text-embedding-ada-002'
6359
},
64-
{
65-
'AI-Resource-Group': 'default'
66-
}
67-
).executeRaw();
60+
metadata: []
61+
},
62+
{
63+
'AI-Resource-Group': 'default'
64+
}
65+
).executeRaw();
6866

6967
const collectionId = (response.headers.location as string).split('/').at(-2);
7068
```

packages/prompt-registry/README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
> [!warning]
2+
> This package is still in **beta** and is subject to breaking changes. Use it with caution.
3+
4+
# @sap-ai-sdk/prompt-registry
5+
6+
SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.
7+
8+
This package incorporates generative AI prompt registry capabilities into your AI activities in SAP AI Core and SAP AI Launchpad.
9+
10+
### Table of Contents
11+
12+
- [Installation](#installation)
13+
- [Prerequisites](#prerequisites)
14+
- [Usage](#usage)
15+
- [List Prompt Templates](#list-prompt-templates)
16+
- [Custom Destination](#custom-destination)
17+
- [Local Testing](#local-testing)
18+
- [Support, Feedback, Contribution](#support-feedback-contribution)
19+
- [License](#license)
20+
21+
## Installation
22+
23+
```
24+
$ npm install @sap-ai-sdk/prompt-registry
25+
```
26+
27+
## Prerequisites
28+
29+
- [Enable the AI Core service in SAP BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
30+
- Configure the project with **Node.js v20 or higher** and **native ESM** support.
31+
32+
> **Accessing the AI Core Service via the SDK**
33+
>
34+
> The SDK automatically retrieves the `AI Core` service credentials and resolves the access token needed for authentication.
35+
>
36+
> - In Cloud Foundry, it's accessed from the `VCAP_SERVICES` environment variable.
37+
> - In Kubernetes / Kyma environments, you have to mount the service binding as a secret instead, for more information refer to [this documentation](https://www.npmjs.com/package/@sap/xsenv#usage-in-kubernetes).
38+
39+
## Usage
40+
41+
The example below demonstrate a sample usage of APIs in SAP AI Core prompt registry service.
42+
43+
In addition, you can find more **sample code** [here](https://github.com/SAP/ai-sdk-js/blob/main/sample-code/src/prompt-registry.ts).
44+
45+
### List Prompt Templates
46+
47+
```ts
48+
const response: PromptTemplateListResponse =
49+
await PromptTemplatesApi.listPromptTemplates({
50+
scenario: 'test'
51+
}).execute();
52+
```
53+
54+
### Custom Destination
55+
56+
When calling the `execute()` method, it is possible to provide a custom destination.
57+
For example, when querying deployments targeting a destination with the name `my-destination`, the following code can be used:
58+
59+
```ts
60+
const response: PromptTemplateListResponse =
61+
await PromptTemplatesApi.listPromptTemplates({
62+
scenario: 'test'
63+
}).execute({
64+
destinationName: 'my-destination'
65+
});
66+
```
67+
68+
## Local Testing
69+
70+
For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).
71+
72+
## Support, Feedback, Contribution
73+
74+
Contribution and feedback are encouraged and always welcome.
75+
For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](https://github.com/SAP/ai-sdk-js/blob/main/CONTRIBUTING.md).
76+
77+
## License
78+
79+
The SAP Cloud SDK for AI is released under the [Apache License Version 2.0](http://www.apache.org/licenses/).
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './dist/internal.js';
2+
//# sourceMappingURL=internal.d.ts.map

packages/prompt-registry/internal.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import config from '../../jest.config.mjs';
2+
export default {
3+
...config,
4+
displayName: 'prompt-registry',
5+
};

packages/prompt-registry/package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@sap-ai-sdk/prompt-registry",
3+
"version": "1.6.0",
4+
"description": "",
5+
"license": "Apache-2.0",
6+
"keywords": [
7+
"sap-ai-sdk",
8+
"ai-api",
9+
"prompt-registry"
10+
],
11+
"type": "module",
12+
"main": "./dist/index.js",
13+
"types": "./dist/index.d.ts",
14+
"files": [
15+
"dist/**/*.js",
16+
"dist/**/*.js.map",
17+
"dist/**/*.d.ts",
18+
"dist/**/*.d.ts.map",
19+
"internal.js",
20+
"internal.d.ts"
21+
],
22+
"scripts": {
23+
"compile": "tsc",
24+
"compile:cjs": "tsc -p tsconfig.cjs.json",
25+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
26+
"lint": "eslint . && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
27+
"lint:fix": "eslint . --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
28+
"generate": "openapi-generator --generateESM --clearOutputDir -i ./src/spec/prompt-registry.yaml -o ./src/client && pnpm update-imports && pnpm lint:fix",
29+
"update-imports": "node --no-warnings --loader ts-node/esm ../../scripts/update-imports.ts ./src/client/prompt-registry"
30+
},
31+
"dependencies": {
32+
"@sap-ai-sdk/core": "workspace:^"
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*
4+
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
5+
*/
6+
export * from './prompt-templates-api.js';
7+
export * from './schema/index.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*
4+
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
5+
*/
6+
import { OpenApiRequestBuilder } from '@sap-ai-sdk/core';
7+
import type {
8+
PromptTemplateListResponse,
9+
PromptTemplatePostRequest,
10+
PromptTemplatePostResponse,
11+
PromptTemplateGetResponse,
12+
PromptTemplateDeleteResponse,
13+
PromptTemplateSubstitutionRequest,
14+
PromptTemplateSubstitutionResponse
15+
} from './schema/index.js';
16+
/**
17+
* Representation of the 'PromptTemplatesApi'.
18+
* This API is part of the 'prompt-registry' service.
19+
*/
20+
export const PromptTemplatesApi = {
21+
_defaultBasePath: undefined,
22+
/**
23+
* List prompt templates
24+
* @param queryParameters - Object containing the following keys: scenario, name, version, retrieve, includeSpec.
25+
* @returns The request builder, use the `execute()` method to trigger the request.
26+
*/
27+
listPromptTemplates: (queryParameters?: {
28+
scenario?: string;
29+
name?: string;
30+
version?: string;
31+
retrieve?: string;
32+
includeSpec?: boolean;
33+
}) =>
34+
new OpenApiRequestBuilder<PromptTemplateListResponse>(
35+
'get',
36+
'/lm/promptTemplates',
37+
{
38+
queryParameters
39+
},
40+
PromptTemplatesApi._defaultBasePath
41+
),
42+
/**
43+
* Create or update a prompt template
44+
* @param body - Request body.
45+
* @returns The request builder, use the `execute()` method to trigger the request.
46+
*/
47+
createUpdatePromptTemplate: (body: PromptTemplatePostRequest) =>
48+
new OpenApiRequestBuilder<PromptTemplatePostResponse>(
49+
'post',
50+
'/lm/promptTemplates',
51+
{
52+
body
53+
},
54+
PromptTemplatesApi._defaultBasePath
55+
),
56+
/**
57+
* List prompt template history
58+
* @param scenario - Path parameter.
59+
* @param version - Path parameter.
60+
* @param name - Path parameter.
61+
* @returns The request builder, use the `execute()` method to trigger the request.
62+
*/
63+
listPromptTemplateHistory: (
64+
scenario: string,
65+
version: string,
66+
name: string
67+
) =>
68+
new OpenApiRequestBuilder<PromptTemplateListResponse>(
69+
'get',
70+
'/lm/scenarios/{scenario}/promptTemplates/{name}/versions/{version}/history',
71+
{
72+
pathParameters: { scenario, version, name }
73+
},
74+
PromptTemplatesApi._defaultBasePath
75+
),
76+
/**
77+
* Get prompt template by UUID
78+
* @param promptTemplateId - Path parameter.
79+
* @returns The request builder, use the `execute()` method to trigger the request.
80+
*/
81+
getPromptTemplateByUuid: (promptTemplateId: string) =>
82+
new OpenApiRequestBuilder<PromptTemplateGetResponse>(
83+
'get',
84+
'/lm/promptTemplates/{promptTemplateId}',
85+
{
86+
pathParameters: { promptTemplateId }
87+
},
88+
PromptTemplatesApi._defaultBasePath
89+
),
90+
/**
91+
* Delete prompt template
92+
* @param promptTemplateId - Path parameter.
93+
* @returns The request builder, use the `execute()` method to trigger the request.
94+
*/
95+
deletePromptTemplate: (promptTemplateId: string) =>
96+
new OpenApiRequestBuilder<PromptTemplateDeleteResponse>(
97+
'delete',
98+
'/lm/promptTemplates/{promptTemplateId}',
99+
{
100+
pathParameters: { promptTemplateId }
101+
},
102+
PromptTemplatesApi._defaultBasePath
103+
),
104+
/**
105+
* Import prompt template
106+
* @param body - Request body.
107+
* @returns The request builder, use the `execute()` method to trigger the request.
108+
*/
109+
importPromptTemplate: (body: any | undefined) =>
110+
new OpenApiRequestBuilder<PromptTemplatePostResponse>(
111+
'post',
112+
'/lm/promptTemplates/import',
113+
{
114+
body
115+
},
116+
PromptTemplatesApi._defaultBasePath
117+
),
118+
/**
119+
* Export prompt template
120+
* @param promptTemplateId - Path parameter.
121+
* @returns The request builder, use the `execute()` method to trigger the request.
122+
*/
123+
exportPromptTemplate: (promptTemplateId: string) =>
124+
new OpenApiRequestBuilder<string>(
125+
'get',
126+
'/lm/promptTemplates/{promptTemplateId}/export',
127+
{
128+
pathParameters: { promptTemplateId }
129+
},
130+
PromptTemplatesApi._defaultBasePath
131+
),
132+
/**
133+
* Parse prompt template by ID
134+
* @param promptTemplateId - Path parameter.
135+
* @param body - Request body.
136+
* @param queryParameters - Object containing the following keys: metadata.
137+
* @returns The request builder, use the `execute()` method to trigger the request.
138+
*/
139+
parsePromptTemplateById: (
140+
promptTemplateId: string,
141+
body: PromptTemplateSubstitutionRequest | undefined,
142+
queryParameters?: { metadata?: boolean }
143+
) =>
144+
new OpenApiRequestBuilder<PromptTemplateSubstitutionResponse>(
145+
'post',
146+
'/lm/promptTemplates/{promptTemplateId}/substitution',
147+
{
148+
pathParameters: { promptTemplateId },
149+
body,
150+
queryParameters
151+
},
152+
PromptTemplatesApi._defaultBasePath
153+
),
154+
/**
155+
* Parse prompt template by name and version
156+
* @param scenario - Path parameter.
157+
* @param version - Path parameter.
158+
* @param name - Path parameter.
159+
* @param body - Request body.
160+
* @param queryParameters - Object containing the following keys: metadata.
161+
* @returns The request builder, use the `execute()` method to trigger the request.
162+
*/
163+
parsePromptTemplateByNameVersion: (
164+
scenario: string,
165+
version: string,
166+
name: string,
167+
body: PromptTemplateSubstitutionRequest | undefined,
168+
queryParameters?: { metadata?: boolean }
169+
) =>
170+
new OpenApiRequestBuilder<PromptTemplateSubstitutionResponse>(
171+
'post',
172+
'/lm/scenarios/{scenario}/promptTemplates/{name}/versions/{version}/substitution',
173+
{
174+
pathParameters: { scenario, version, name },
175+
body,
176+
queryParameters
177+
},
178+
PromptTemplatesApi._defaultBasePath
179+
)
180+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*
4+
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
5+
*/
6+
import type { FunctionObject } from './function-object.js';
7+
/**
8+
* Representation of the 'ChatCompletionTool' schema.
9+
*/
10+
export type ChatCompletionTool = {
11+
/**
12+
* The type of the tool. Currently, only `function` is supported.
13+
*/
14+
type: 'function';
15+
function: FunctionObject;
16+
};

0 commit comments

Comments
 (0)