@sap-ai-sdk/foundation-models 1.11.1-20250414013204.0 → 1.11.1-20250415115505.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +3 -285
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -7,17 +7,7 @@ This package incorporates generative AI foundation models into your AI activitie
7
7
  ### Table of Contents
8
8
 
9
9
  - [Installation](#installation)
10
- - [Prerequisites](#prerequisites)
11
- - [Relationship between Models and Deployment ID](#relationship-between-models-and-deployment-id)
12
- - [Usage](#usage)
13
- - [Azure OpenAI Client Initialization](#azure-openai-client-initialization)
14
- - [Azure OpenAI Chat Client](#azure-openai-chat-client)
15
- - [Azure OpenAI Embedding Client](#azure-openai-embedding-client)
16
- - [Custom Request Configuration](#custom-request-configuration)
17
- - [Custom Destination](#custom-destination)
18
- - [Overwriting API Version](#overwriting-api-version)
19
- - [Error Handling](#error-handling)
20
- - [Local Testing](#local-testing)
10
+ - [Documentation](#documentation)
21
11
  - [Support, Feedback, Contribution](#support-feedback-contribution)
22
12
  - [License](#license)
23
13
 
@@ -27,281 +17,9 @@ This package incorporates generative AI foundation models into your AI activitie
27
17
  $ npm install @sap-ai-sdk/foundation-models
28
18
  ```
29
19
 
30
- ## Prerequisites
20
+ ## Documentation
31
21
 
32
- - [Enable the AI Core service in SAP BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
33
- - Configure the project with **Node.js v20 or higher** and **native ESM** support.
34
- - Ensure a deployed OpenAI model is available in the SAP Generative AI Hub.
35
- - Use the [`DeploymentApi`](https://github.com/SAP/ai-sdk-js/blob/main/packages/ai-api/README.md#create-a-deployment) from `@sap-ai-sdk/ai-api` [to deploy a model](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
36
- Alternatively, you can also create deployments using the [SAP AI Launchpad](https://help.sap.com/docs/sap-ai-core/generative-ai-hub/activate-generative-ai-hub-for-sap-ai-launchpad?locale=en-US&q=launchpad).
37
- Deployment can be set up for each model and model version, as well as a resource group.
38
- - Once a deployment is complete, access the model via the `deploymentUrl`.
39
-
40
- > **Accessing the AI Core Service via the SDK**
41
- >
42
- > The SDK automatically retrieves the `AI Core` service credentials and resolves the access token needed for authentication.
43
- >
44
- > - In Cloud Foundry, it's accessed from the `VCAP_SERVICES` environment variable.
45
- > - 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).
46
-
47
- ## Relationship between Models and Deployment ID
48
-
49
- SAP AI Core manages access to generative AI models through the global AI scenario `foundation-models`.
50
- Creating a deployment for a model requires access to this scenario.
51
-
52
- Each model, model version, and resource group allows for a one-time deployment.
53
- After deployment completion, the response includes a `deploymentUrl` and an `id`, which is the deployment ID.
54
- For more information, see [here](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-generative-ai-model-in-sap-ai-core).
55
- [Resource groups](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/resource-groups?q=resource+group) represent a virtual collection of related resources within the scope of one SAP AI Core tenant.
56
-
57
- Consequently, each deployment ID and resource group uniquely map to a combination of model and model version within the `foundation-models` scenario.
58
-
59
- ## Usage
60
-
61
- ### Azure OpenAI Client Initialization
62
-
63
- You can pass the model name as a parameter to a client, the SDK will implicitly fetch the deployment ID for the model from the AI Core service and use it in the request.
64
-
65
- By default, the SDK caches the deployment information, including the deployment ID, model name, and version, for 5 minutes to avoid performance issues from fetching this data with each request.
66
-
67
- ```ts
68
- import {
69
- AzureOpenAiChatClient,
70
- AzureOpenAiEmbeddingClient
71
- } from '@sap-ai-sdk/foundation-models';
72
-
73
- // For a chat client
74
- const chatClient = new AzureOpenAiChatClient({ modelName: 'gpt-4o' });
75
- // For an embedding client
76
- const embeddingClient = new AzureOpenAiEmbeddingClient({ modelName: 'gpt-4o' });
77
- ```
78
-
79
- The deployment ID and resource group can be used as an alternative to the model name for obtaining a model.
80
-
81
- ```ts
82
- const chatClient = new AzureOpenAiChatClient({
83
- deploymentId: 'd1234',
84
- resourceGroup: 'rg1234'
85
- });
86
- ```
87
-
88
- ### Azure OpenAI Chat Client
89
-
90
- #### Making Requests
91
-
92
- Use the `AzureOpenAiChatClient` to send chat completion requests to an OpenAI model deployed in SAP generative AI hub.
93
-
94
- The client sends request with Azure OpenAI API version `2024-10-21`.
95
-
96
- ```ts
97
- import { AzureOpenAiChatClient } from '@sap-ai-sdk/foundation-models';
98
-
99
- const chatClient = new AzureOpenAiChatClient('gpt-4o');
100
- const response = await chatClient.run({
101
- messages: [
102
- {
103
- role: 'user',
104
- content: 'Where is the deepest place on earth located'
105
- }
106
- ]
107
- });
108
-
109
- const responseContent = response.getContent();
110
- ```
111
-
112
- Multiple messages can be sent in a single request, enabling the model to reference the conversation history.
113
- Include parameters like `max_tokens` and `temperature` in the request to control the completion behavior:
114
-
115
- ```ts
116
- const response = await chatClient.run({
117
- messages: [
118
- {
119
- role: 'system',
120
- content: 'You are a friendly chatbot.'
121
- },
122
- {
123
- role: 'user',
124
- content: 'Hi, my name is Isa'
125
- },
126
- {
127
- role: 'assistant',
128
- content:
129
- 'Hi Isa! It is nice to meet you. Is there anything I can help you with today?'
130
- },
131
- {
132
- role: 'user',
133
- content: 'Can you remind me, What is my name?'
134
- }
135
- ],
136
- max_tokens: 100,
137
- temperature: 0.0
138
- });
139
-
140
- const responseContent = response.getContent();
141
- const tokenUsage = response.getTokenUsage();
142
-
143
- console.log(
144
- `Total tokens consumed by the request: ${tokenUsage.total_tokens}\n` +
145
- `Input prompt tokens consumed: ${tokenUsage.prompt_tokens}\n` +
146
- `Output text completion tokens consumed: ${tokenUsage.completion_tokens}\n`
147
- );
148
- ```
149
-
150
- Refer to `AzureOpenAiChatCompletionParameters` interface for other parameters that can be passed to the chat completion request.
151
-
152
- #### Streaming
153
-
154
- The `AzureOpenAiChatClient` supports streaming response for chat completion requests based on the [Server-sent events](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) standard.
155
-
156
- Use the `stream()` method to receive a stream of chunk responses from the model.
157
- After consuming the stream, call the helper methods to get the finish reason and token usage information.
158
-
159
- ```ts
160
- const chatClient = new AzureOpenAiChatClient('gpt-4o');
161
- const response = await chatClient.stream({
162
- messages: [
163
- {
164
- role: 'user',
165
- content: 'Give me a very long introduction of SAP Cloud SDK.'
166
- }
167
- ]
168
- });
169
-
170
- for await (const chunk of response.stream) {
171
- console.log(JSON.stringify(chunk));
172
- }
173
-
174
- const finishReason = response.getFinishReason();
175
- const tokenUsage = response.getTokenUsage();
176
-
177
- console.log(`Finish reason: ${finishReason}\n`);
178
- console.log(`Token usage: ${JSON.stringify(tokenUsage)}\n`);
179
- ```
180
-
181
- ##### Streaming the Delta Content
182
-
183
- The client provides a helper method to extract the text chunks as strings:
184
-
185
- ```ts
186
- for await (const chunk of response.stream.toContentStream()) {
187
- console.log(chunk); // will log the delta content
188
- }
189
- ```
190
-
191
- Each chunk will be a defined string containing the delta content.
192
- Set `choiceIndex` parameter for `toContentStream()` method to stream a specific choice.
193
-
194
- ##### Streaming with Abort Controller
195
-
196
- Streaming request can be aborted using the `AbortController` API.
197
- In case of an error, the SAP Cloud SDK for AI will automatically close the stream.
198
- Additionally, it can be aborted manually by calling the `stream()` method with an `AbortController` object.
199
-
200
- ```ts
201
- const chatClient = new AzureOpenAiChatClient('gpt-4o');
202
- const controller = new AbortController();
203
- const response = await chatClient.stream(
204
- {
205
- messages: [
206
- {
207
- role: 'user',
208
- content: 'Give me a very long introduction of SAP Cloud SDK.'
209
- }
210
- ]
211
- },
212
- controller
213
- );
214
-
215
- // Abort the streaming request after one second
216
- setTimeout(() => {
217
- controller.abort();
218
- }, 1000);
219
-
220
- for await (const chunk of response.stream) {
221
- console.log(JSON.stringify(chunk));
222
- }
223
- ```
224
-
225
- In this example, streaming request will be aborted after one second.
226
- Abort controller can be useful, e.g., when end-user wants to stop the stream or refreshes the page.
227
-
228
- ### Azure OpenAI Embedding Client
229
-
230
- Use the `AzureOpenAiEmbeddingClient` to send embedding requests to an OpenAI model deployed in SAP generative AI hub.
231
-
232
- ```ts
233
- import { AzureOpenAiEmbeddingClient } from '@sap-ai-sdk/foundation-models';
234
-
235
- const embeddingClient = new AzureOpenAiEmbeddingClient(
236
- 'text-embedding-3-small'
237
- );
238
- const response = await embeddingClient.run({
239
- input: 'AI is fascinating'
240
- });
241
- const embedding = response.getEmbedding();
242
- ```
243
-
244
- ### Custom Request Configuration
245
-
246
- Set custom request configuration in the `requestConfig` parameter when calling the `run()` method of a chat or embedding client.
247
-
248
- ```ts
249
- const response = await client.run(
250
- {
251
- ...
252
- },
253
- {
254
- headers: {
255
- 'x-custom-header': 'custom-value'
256
- // Add more headers here
257
- },
258
- params: {
259
- // Add more parameters here
260
- }
261
- // Add more request configuration here
262
- }
263
- );
264
- ```
265
-
266
- ### Custom Destination
267
-
268
- When initializing the `AzureOpenAiChatClient` and `AzureOpenAiEmbeddingClient` clients, it is possible to provide a custom destination.
269
- For example, when targeting a destination with the name `my-destination`, the following code can be used:
270
-
271
- ```ts
272
- const client = await new AzureOpenAiChatClient('gpt-4o', {
273
- destinationName: 'my-destination'
274
- });
275
- ```
276
-
277
- By default, the fetched destination is cached.
278
- To disable caching, set the `useCache` parameter to `false` together with the `destinationName` parameter.
279
-
280
- ### Overwriting API Version
281
-
282
- We are continuously updating the OpenAI API version to match the latest version.
283
- In case this behavior causes issues in your application, you can overwrite the API version.
284
-
285
- To do this, set the `api-version` parameter in the `CustomRequestConfig` object, like the following:
286
-
287
- ```ts
288
- const client = await new AzureOpenAiChatClient('gpt-4o', {
289
- destinationName: 'my-destination'
290
- });
291
-
292
- client.run(
293
- { messages: [{ role: 'user', content: 'YOUR_PROMPT' }] },
294
- { params: { 'api-version': 'YOUR_OLD_VERSION' } }
295
- );
296
- ```
297
-
298
- ## Error Handling
299
-
300
- For error handling instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#error-handling).
301
-
302
- ## Local Testing
303
-
304
- For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).
22
+ Visit the [SAP Cloud SDK for AI (JavaScript)](https://sap.github.io/ai-sdk/docs/js/overview-cloud-sdk-for-ai-js) documentation portal to learn more about its capabilities and detailed usage.
305
23
 
306
24
  ## Support, Feedback, Contribution
307
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ai-sdk/foundation-models",
3
- "version": "1.11.1-20250414013204.0",
3
+ "version": "1.11.1-20250415115505.0",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -23,8 +23,8 @@
23
23
  "@sap-cloud-sdk/http-client": "^4.0.2",
24
24
  "@sap-cloud-sdk/util": "^4.0.2",
25
25
  "@sap-cloud-sdk/connectivity": "^4.0.2",
26
- "@sap-ai-sdk/ai-api": "^1.11.1-20250414013204.0",
27
- "@sap-ai-sdk/core": "^1.11.1-20250414013204.0"
26
+ "@sap-ai-sdk/ai-api": "^1.11.1-20250415115505.0",
27
+ "@sap-ai-sdk/core": "^1.11.1-20250415115505.0"
28
28
  },
29
29
  "scripts": {
30
30
  "compile": "tsc",