@sap-ai-sdk/ai-api 1.8.1-20250306013127.0 → 1.9.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.
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ We maintain a list of [currently available and tested AI Core APIs](https://gith
|
|
|
22
22
|
- [Create a Deployment](#create-a-deployment)
|
|
23
23
|
- [Delete a Deployment](#delete-a-deployment)
|
|
24
24
|
- [Custom Destination](#custom-destination)
|
|
25
|
+
- [Error Handling](#error-handling)
|
|
25
26
|
- [Local Testing](#local-testing)
|
|
26
27
|
- [Support, Feedback, Contribution](#support-feedback-contribution)
|
|
27
28
|
- [License](#license)
|
|
@@ -73,17 +74,11 @@ async function createArtifact() {
|
|
|
73
74
|
scenarioId: 'foundation-models'
|
|
74
75
|
};
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return responseData;
|
|
82
|
-
} catch (errorData) {
|
|
83
|
-
const apiError = errorData.response.data.error as ApiError;
|
|
84
|
-
console.error('Status code:', errorData.response.status);
|
|
85
|
-
throw new Error(`Artifact creation failed: ${apiError.message}`);
|
|
86
|
-
}
|
|
77
|
+
const responseData: ArtifactCreationResponse =
|
|
78
|
+
await ArtifactApi.artifactCreate(requestBody, {
|
|
79
|
+
'AI-Resource-Group': 'default'
|
|
80
|
+
}).execute();
|
|
81
|
+
return responseData;
|
|
87
82
|
}
|
|
88
83
|
```
|
|
89
84
|
|
|
@@ -108,39 +103,26 @@ async function createConfiguration() {
|
|
|
108
103
|
inputArtifactBindings: []
|
|
109
104
|
};
|
|
110
105
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return responseData;
|
|
117
|
-
} catch (errorData) {
|
|
118
|
-
const apiError = errorData.response.data.error as ApiError;
|
|
119
|
-
console.error('Status code:', errorData.response.status);
|
|
120
|
-
throw new Error(`Configuration creation failed: ${apiError.message}`);
|
|
121
|
-
}
|
|
106
|
+
const responseData: ConfigurationCreationResponse =
|
|
107
|
+
await ConfigurationApi.configurationCreate(requestBody, {
|
|
108
|
+
'AI-Resource-Group': 'default'
|
|
109
|
+
}).execute();
|
|
110
|
+
return responseData;
|
|
122
111
|
}
|
|
123
112
|
```
|
|
124
113
|
|
|
125
114
|
### Create a Deployment
|
|
126
115
|
|
|
127
|
-
```
|
|
116
|
+
```ts
|
|
128
117
|
async function createDeployment() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.execute();
|
|
138
|
-
return responseData;
|
|
139
|
-
} catch (errorData) {
|
|
140
|
-
const apiError = errorData.response.data.error as ApiError;
|
|
141
|
-
console.error('Status code:', errorData.response.status);
|
|
142
|
-
throw new Error(`Deployment creation failed: ${apiError.message}`);
|
|
143
|
-
}
|
|
118
|
+
const requestBody: DeploymentCreationRequest = {
|
|
119
|
+
configurationId: '0a1b2c3d-4e5f6g7h'
|
|
120
|
+
};
|
|
121
|
+
const responseData: DeploymentCreationResponse =
|
|
122
|
+
await DeploymentApi.deploymentCreate(requestBody, {
|
|
123
|
+
'AI-Resource-Group': 'default'
|
|
124
|
+
}).execute();
|
|
125
|
+
return responseData;
|
|
144
126
|
}
|
|
145
127
|
```
|
|
146
128
|
|
|
@@ -166,26 +148,14 @@ async function modifyDeployment() {
|
|
|
166
148
|
targetStatus: 'STOPPED'
|
|
167
149
|
};
|
|
168
150
|
|
|
169
|
-
|
|
170
|
-
await DeploymentApi.deploymentModify(deploymentId, requestBody, {
|
|
171
|
-
'AI-Resource-Group': 'default'
|
|
172
|
-
}).execute();
|
|
173
|
-
} catch (errorData) {
|
|
174
|
-
const apiError = errorData.response.data.error as ApiError;
|
|
175
|
-
console.error('Status code:', errorData.response.status);
|
|
176
|
-
throw new Error(`Deployment modification failed: ${apiError.message}`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
// Wait a few seconds for the deployment to stop
|
|
180
|
-
try {
|
|
181
|
-
return DeploymentApi.deploymentDelete(deploymentId, {
|
|
151
|
+
await DeploymentApi.deploymentModify(deploymentId, requestBody, {
|
|
182
152
|
'AI-Resource-Group': 'default'
|
|
183
153
|
}).execute();
|
|
184
|
-
} catch (errorData) {
|
|
185
|
-
const apiError = errorData.response.data.error as ApiError;
|
|
186
|
-
console.error('Status code:', errorData.response.status);
|
|
187
|
-
throw new Error(`Deployment deletion failed: ${apiError.message}`);
|
|
188
154
|
}
|
|
155
|
+
// Wait a few seconds for the deployment to stop
|
|
156
|
+
return DeploymentApi.deploymentDelete(deploymentId, {
|
|
157
|
+
'AI-Resource-Group': 'default'
|
|
158
|
+
}).execute();
|
|
189
159
|
}
|
|
190
160
|
```
|
|
191
161
|
|
|
@@ -206,6 +176,10 @@ return DeploymentApi.deploymentQuery(queryParams, {
|
|
|
206
176
|
By default, the fetched destination is cached.
|
|
207
177
|
To disable caching, set the `useCache` parameter to `false` together with the `destinationName` parameter.
|
|
208
178
|
|
|
179
|
+
## Error Handling
|
|
180
|
+
|
|
181
|
+
For error handling instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#error-handling).
|
|
182
|
+
|
|
209
183
|
## Local Testing
|
|
210
184
|
|
|
211
185
|
For local testing instructions, refer to this [section](https://github.com/SAP/ai-sdk-js/blob/main/README.md#local-testing).
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AiDeployment } from '../client/AI_CORE_API/index.js';
|
|
1
2
|
import { type FoundationModel } from './model.js';
|
|
2
3
|
import type { HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity';
|
|
3
4
|
/**
|
|
@@ -74,6 +75,13 @@ export interface DeploymentResolutionOptions {
|
|
|
74
75
|
* @internal
|
|
75
76
|
*/
|
|
76
77
|
export declare function resolveDeploymentId(opts: DeploymentResolutionOptions): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Get all deployments that match the given criteria.
|
|
80
|
+
* @param opts - The options for the deployment resolution.
|
|
81
|
+
* @returns A promise of an array of deployments.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export declare function getAllDeployments(opts: DeploymentResolutionOptions): Promise<AiDeployment[]>;
|
|
77
85
|
/**
|
|
78
86
|
* Get the deployment ID for a given model deployment configuration and executable ID using the 'foundation-models' scenario.
|
|
79
87
|
* @param modelDeployment - The model deployment configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/deployment-resolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deployment-resolver.d.ts","sourceRoot":"","sources":["../../src/utils/deployment-resolver.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAEjF;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,UAAU,GAAG,MAAM;IAC9C;;OAEG;IACH,SAAS,EAAE,UAAU,CAAC;IACtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,UAAU,GAAG,MAAM,IAC3C,UAAU,GACV,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,kBAAkB,CAAC,GAAG,mBAAmB,CAAC,CAAC;AAE3E;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS,CAIpB;AAeD;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,CAAC,EAAE,6BAA6B,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC,YAAY,EAAE,CAAC,CAuBzB;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,6BAA6B,GAC1C,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ErrorWithCause } from '@sap-cloud-sdk/util';
|
|
1
2
|
import { DeploymentApi } from '../client/AI_CORE_API/index.js';
|
|
2
3
|
import { deploymentCache } from './deployment-cache.js';
|
|
3
4
|
import { extractModel } from './model.js';
|
|
@@ -41,7 +42,13 @@ export async function resolveDeploymentId(opts) {
|
|
|
41
42
|
}
|
|
42
43
|
return deployments[0].id;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Get all deployments that match the given criteria.
|
|
47
|
+
* @param opts - The options for the deployment resolution.
|
|
48
|
+
* @returns A promise of an array of deployments.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export async function getAllDeployments(opts) {
|
|
45
52
|
const { destination, scenarioId, executableId, resourceGroup = 'default' } = opts;
|
|
46
53
|
try {
|
|
47
54
|
const { resources } = await DeploymentApi.deploymentQuery({
|
|
@@ -53,7 +60,7 @@ async function getAllDeployments(opts) {
|
|
|
53
60
|
return resources;
|
|
54
61
|
}
|
|
55
62
|
catch (error) {
|
|
56
|
-
throw new
|
|
63
|
+
throw new ErrorWithCause('Failed to fetch the list of deployments.', error);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deployment-resolver.js","sourceRoot":"","sources":["../../src/utils/deployment-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAwB,MAAM,YAAY,CAAC;AA8ChE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,eAAgC;IAEhC,OAAO,OAAO,eAAe,KAAK,QAAQ;QACxC,CAAC,CAAC,eAAe,CAAC,aAAa;QAC/B,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAC3B,eAAgC;IAEhC,OAAO,CACL,OAAO,eAAe,KAAK,QAAQ,IAAI,cAAc,IAAI,eAAe,CACzE,CAAC;AACJ,CAAC;AA6BD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAiC;IAEjC,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEvB,MAAM,gBAAgB,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnD,IAAI,gBAAgB,EAAE,EAAE,EAAE,CAAC;QACzB,OAAO,gBAAgB,CAAC,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,WAAW,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAEhD,IAAI,KAAK,EAAE,CAAC;QACV,WAAW,GAAG,WAAW,CAA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|
+
"version": "1.9.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@sap-cloud-sdk/connectivity": "^4.0.1",
|
|
23
|
-
"@sap-
|
|
23
|
+
"@sap-cloud-sdk/util": "^4.0.1",
|
|
24
|
+
"@sap-ai-sdk/core": "^1.9.0"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"compile": "tsc",
|