@sap-ai-sdk/foundation-models 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @sap-ai-sdk/foundation-models
2
+
3
+ This package incorporates generative AI foundation models into your AI activities in SAP AI Core and SAP AI Launchpad.
4
+
5
+ ### Installation
6
+
7
+ ```
8
+ $ npm install @sap-ai-sdk/foundation-models
9
+ ```
10
+
11
+ ## Pre-requisites
12
+
13
+ - [Enable the AI Core service in BTP](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup).
14
+ - Project configured with Node.js v20 or higher and native ESM support enabled.
15
+ - For testing your application locally:
16
+ - Download a service key for your AI Core service instance.
17
+ - Create a `.env` file in the sample-code directory.
18
+ - Add an entry `AICORE_SERVICE_KEY='<content-of-service-key>'`.
19
+
20
+ ## Usage
21
+
22
+ <!-- Details to be added -->
23
+
24
+ ## Support, Feedback, Contribution
25
+
26
+ This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/ai-sdk-js/issues).
27
+
28
+ Contribution and feedback are encouraged and always welcome. 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).
29
+
30
+ ## License
31
+
32
+ The SAP Cloud SDK for AI is released under the [Apache License Version 2.0.](http://www.apache.org/licenses/)
@@ -0,0 +1,3 @@
1
+ export type { OpenAiChatModel, OpenAiEmbeddingModel, OpenAiChatMessage, OpenAiChatSystemMessage, OpenAiChatUserMessage, OpenAiChatAssistantMessage, OpenAiChatToolMessage, OpenAiChatFunctionMessage, OpenAiCompletionChoice, OpenAiErrorBase, OpenAiChatCompletionChoice, OpenAiCompletionOutput, OpenAiUsage, OpenAiChatCompletionFunction, OpenAiChatCompletionTool, OpenAiChatFunctionCall, OpenAiChatToolCall, OpenAiCompletionParameters, OpenAiChatCompletionParameters, OpenAiEmbeddingParameters, OpenAiChatCompletionOutput, OpenAiPromptFilterResult, OpenAiContentFilterResultsBase, OpenAiContentFilterPromptResults, OpenAiContentFilterResultBase, OpenAiContentFilterDetectedResult, OpenAiContentFilterSeverityResult, OpenAiEmbeddingOutput } from './openai/index.js';
2
+ export { OpenAiChatClient, OpenAiEmbeddingClient, OpenAiChatCompletionResponse } from './openai/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,WAAW,EACX,4BAA4B,EAC5B,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,gCAAgC,EAChC,6BAA6B,EAC7B,iCAAiC,EACjC,iCAAiC,EACjC,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { OpenAiChatClient, OpenAiEmbeddingClient, OpenAiChatCompletionResponse } from './openai/index.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8BA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './openai/index.js';
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './openai/index.js';
2
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './openai-types.js';
2
+ export * from './openai-chat-client.js';
3
+ export * from './openai-embedding-client.js';
4
+ export * from './openai-response.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './openai-types.js';
2
+ export * from './openai-chat-client.js';
3
+ export * from './openai-embedding-client.js';
4
+ export * from './openai-response.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/openai/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type CustomRequestConfig } from '@sap-ai-sdk/core';
2
+ import { type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js';
3
+ import type { OpenAiChatCompletionParameters, OpenAiChatModel } from './openai-types.js';
4
+ import { OpenAiChatCompletionResponse } from './openai-response.js';
5
+ /**
6
+ * OpenAI client for chat completion.
7
+ */
8
+ export declare class OpenAiChatClient {
9
+ private modelDeployment;
10
+ /**
11
+ * Creates an instance of the OpenAI chat client.
12
+ * @param modelDeployment - This configuration is used to retrieve a deployment. Depending on the configuration use either the given deployment ID or the model name to retrieve matching deployments. If model and deployment ID are given, the model is verified against the deployment.
13
+ */
14
+ constructor(modelDeployment: ModelDeployment<OpenAiChatModel>);
15
+ /**
16
+ * Creates a completion for the chat messages.
17
+ * @param data - The input parameters for the chat completion.
18
+ * @param requestConfig - The request configuration.
19
+ * @returns The completion result.
20
+ */
21
+ run(data: OpenAiChatCompletionParameters, requestConfig?: CustomRequestConfig): Promise<OpenAiChatCompletionResponse>;
22
+ }
23
+ //# sourceMappingURL=openai-chat-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-chat-client.d.ts","sourceRoot":"","sources":["../../src/openai/openai-chat-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,8BAA8B,EAC9B,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAIpE;;GAEG;AACH,qBAAa,gBAAgB;IAKf,OAAO,CAAC,eAAe;IAJnC;;;OAGG;gBACiB,eAAe,EAAE,eAAe,CAAC,eAAe,CAAC;IAErE;;;;;OAKG;IACG,GAAG,CACP,IAAI,EAAE,8BAA8B,EACpC,aAAa,CAAC,EAAE,mBAAmB,GAClC,OAAO,CAAC,4BAA4B,CAAC;CAezC"}
@@ -0,0 +1,32 @@
1
+ import { executeRequest } from '@sap-ai-sdk/core';
2
+ import { getDeploymentId } from '@sap-ai-sdk/ai-api/internal.js';
3
+ import { OpenAiChatCompletionResponse } from './openai-response.js';
4
+ const apiVersion = '2024-02-01';
5
+ /**
6
+ * OpenAI client for chat completion.
7
+ */
8
+ export class OpenAiChatClient {
9
+ modelDeployment;
10
+ /**
11
+ * Creates an instance of the OpenAI chat client.
12
+ * @param modelDeployment - This configuration is used to retrieve a deployment. Depending on the configuration use either the given deployment ID or the model name to retrieve matching deployments. If model and deployment ID are given, the model is verified against the deployment.
13
+ */
14
+ constructor(modelDeployment) {
15
+ this.modelDeployment = modelDeployment;
16
+ }
17
+ /**
18
+ * Creates a completion for the chat messages.
19
+ * @param data - The input parameters for the chat completion.
20
+ * @param requestConfig - The request configuration.
21
+ * @returns The completion result.
22
+ */
23
+ async run(data, requestConfig) {
24
+ const deploymentId = await getDeploymentId(this.modelDeployment, 'azure-openai');
25
+ const response = await executeRequest({
26
+ url: `/inference/deployments/${deploymentId}/chat/completions`,
27
+ apiVersion
28
+ }, data, requestConfig);
29
+ return new OpenAiChatCompletionResponse(response);
30
+ }
31
+ }
32
+ //# sourceMappingURL=openai-chat-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-chat-client.js","sourceRoot":"","sources":["../../src/openai/openai-chat-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAKxC,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEpE,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAKP;IAJpB;;;OAGG;IACH,YAAoB,eAAiD;QAAjD,oBAAe,GAAf,eAAe,CAAkC;IAAG,CAAC;IAEzE;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,IAAoC,EACpC,aAAmC;QAEnC,MAAM,YAAY,GAAG,MAAM,eAAe,CACxC,IAAI,CAAC,eAAe,EACpB,cAAc,CACf,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,cAAc,CACnC;YACE,GAAG,EAAE,0BAA0B,YAAY,mBAAmB;YAC9D,UAAU;SACX,EACD,IAAI,EACJ,aAAa,CACd,CAAC;QACF,OAAO,IAAI,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { type CustomRequestConfig } from '@sap-ai-sdk/core';
2
+ import { type ModelDeployment } from '@sap-ai-sdk/ai-api/internal.js';
3
+ import type { OpenAiEmbeddingParameters, OpenAiEmbeddingOutput, OpenAiEmbeddingModel } from './openai-types.js';
4
+ /**
5
+ * OpenAI client for embeddings.
6
+ */
7
+ export declare class OpenAiEmbeddingClient {
8
+ private modelDeployment;
9
+ /**
10
+ * Creates an instance of the OpenAI embedding client.
11
+ * @param modelDeployment - This configuration is used to retrieve a deployment. Depending on the configuration use either the given deployment ID or the model name to retrieve matching deployments. If model and deployment ID are given, the model is verified against the deployment.
12
+ */
13
+ constructor(modelDeployment: ModelDeployment<OpenAiEmbeddingModel>);
14
+ /**
15
+ * Creates an embedding vector representing the given text.
16
+ * @param data - The text to embed.
17
+ * @param requestConfig - The request configuration.
18
+ * @returns The completion result.
19
+ */
20
+ run(data: OpenAiEmbeddingParameters, requestConfig?: CustomRequestConfig): Promise<OpenAiEmbeddingOutput>;
21
+ }
22
+ //# sourceMappingURL=openai-embedding-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-embedding-client.d.ts","sourceRoot":"","sources":["../../src/openai/openai-embedding-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAkB,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAI3B;;GAEG;AACH,qBAAa,qBAAqB;IAKpB,OAAO,CAAC,eAAe;IAJnC;;;OAGG;gBACiB,eAAe,EAAE,eAAe,CAAC,oBAAoB,CAAC;IAE1E;;;;;OAKG;IACG,GAAG,CACP,IAAI,EAAE,yBAAyB,EAC/B,aAAa,CAAC,EAAE,mBAAmB,GAClC,OAAO,CAAC,qBAAqB,CAAC;CAYlC"}
@@ -0,0 +1,28 @@
1
+ import { executeRequest } from '@sap-ai-sdk/core';
2
+ import { getDeploymentId } from '@sap-ai-sdk/ai-api/internal.js';
3
+ const apiVersion = '2024-02-01';
4
+ /**
5
+ * OpenAI client for embeddings.
6
+ */
7
+ export class OpenAiEmbeddingClient {
8
+ modelDeployment;
9
+ /**
10
+ * Creates an instance of the OpenAI embedding client.
11
+ * @param modelDeployment - This configuration is used to retrieve a deployment. Depending on the configuration use either the given deployment ID or the model name to retrieve matching deployments. If model and deployment ID are given, the model is verified against the deployment.
12
+ */
13
+ constructor(modelDeployment) {
14
+ this.modelDeployment = modelDeployment;
15
+ }
16
+ /**
17
+ * Creates an embedding vector representing the given text.
18
+ * @param data - The text to embed.
19
+ * @param requestConfig - The request configuration.
20
+ * @returns The completion result.
21
+ */
22
+ async run(data, requestConfig) {
23
+ const deploymentId = await getDeploymentId(this.modelDeployment, 'azure-openai');
24
+ const response = await executeRequest({ url: `/inference/deployments/${deploymentId}/embeddings`, apiVersion }, data, requestConfig);
25
+ return response.data;
26
+ }
27
+ }
28
+ //# sourceMappingURL=openai-embedding-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-embedding-client.js","sourceRoot":"","sources":["../../src/openai/openai-embedding-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAOxC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAKZ;IAJpB;;;OAGG;IACH,YAAoB,eAAsD;QAAtD,oBAAe,GAAf,eAAe,CAAuC;IAAG,CAAC;IAE9E;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,IAA+B,EAC/B,aAAmC;QAEnC,MAAM,YAAY,GAAG,MAAM,eAAe,CACxC,IAAI,CAAC,eAAe,EACpB,cAAc,CACf,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,cAAc,CACnC,EAAE,GAAG,EAAE,0BAA0B,YAAY,aAAa,EAAE,UAAU,EAAE,EACxE,IAAI,EACJ,aAAa,CACd,CAAC;QACF,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import { HttpResponse } from '@sap-cloud-sdk/http-client';
2
+ import { OpenAiChatCompletionOutput, OpenAiUsage } from './openai-types.js';
3
+ /**
4
+ * OpenAI chat completion response.
5
+ */
6
+ export declare class OpenAiChatCompletionResponse {
7
+ readonly rawResponse: HttpResponse;
8
+ /**
9
+ * The chat completion response.
10
+ */
11
+ readonly data: OpenAiChatCompletionOutput;
12
+ constructor(rawResponse: HttpResponse);
13
+ /**
14
+ * Usage of tokens in the response.
15
+ * @returns Token usage.
16
+ */
17
+ getTokenUsage(): OpenAiUsage;
18
+ /**
19
+ * Reason for stopping the completion.
20
+ * @param choiceIndex - The index of the choice to parse.
21
+ * @returns The finish reason.
22
+ */
23
+ getFinishReason(choiceIndex?: number): string | undefined;
24
+ /**
25
+ * Parses the Open AI response and returns the content.
26
+ * @param choiceIndex - The index of the choice to parse.
27
+ * @returns The message content.
28
+ */
29
+ getContent(choiceIndex?: number): string | undefined;
30
+ private logInvalidChoiceIndex;
31
+ }
32
+ //# sourceMappingURL=openai-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-response.d.ts","sourceRoot":"","sources":["../../src/openai/openai-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAO5E;;GAEG;AACH,qBAAa,4BAA4B;aAKX,WAAW,EAAE,YAAY;IAJrD;;OAEG;IACH,SAAgB,IAAI,EAAE,0BAA0B,CAAC;gBACrB,WAAW,EAAE,YAAY;IAIrD;;;OAGG;IACH,aAAa,IAAI,WAAW;IAI5B;;;;OAIG;IACH,eAAe,CAAC,WAAW,SAAI,GAAG,MAAM,GAAG,SAAS;IAKpD;;;;OAIG;IACH,UAAU,CAAC,WAAW,SAAI,GAAG,MAAM,GAAG,SAAS;IAK/C,OAAO,CAAC,qBAAqB;CAK9B"}
@@ -0,0 +1,50 @@
1
+ import { createLogger } from '@sap-cloud-sdk/util';
2
+ const logger = createLogger({
3
+ package: 'gen-ai-hub',
4
+ messageContext: 'openai-response'
5
+ });
6
+ /**
7
+ * OpenAI chat completion response.
8
+ */
9
+ export class OpenAiChatCompletionResponse {
10
+ rawResponse;
11
+ /**
12
+ * The chat completion response.
13
+ */
14
+ data;
15
+ constructor(rawResponse) {
16
+ this.rawResponse = rawResponse;
17
+ this.data = rawResponse.data;
18
+ }
19
+ /**
20
+ * Usage of tokens in the response.
21
+ * @returns Token usage.
22
+ */
23
+ getTokenUsage() {
24
+ return this.data.usage;
25
+ }
26
+ /**
27
+ * Reason for stopping the completion.
28
+ * @param choiceIndex - The index of the choice to parse.
29
+ * @returns The finish reason.
30
+ */
31
+ getFinishReason(choiceIndex = 0) {
32
+ this.logInvalidChoiceIndex(choiceIndex);
33
+ return this.data.choices[choiceIndex]?.finish_reason;
34
+ }
35
+ /**
36
+ * Parses the Open AI response and returns the content.
37
+ * @param choiceIndex - The index of the choice to parse.
38
+ * @returns The message content.
39
+ */
40
+ getContent(choiceIndex = 0) {
41
+ this.logInvalidChoiceIndex(choiceIndex);
42
+ return this.data.choices[choiceIndex]?.message?.content;
43
+ }
44
+ logInvalidChoiceIndex(choiceIndex) {
45
+ if (choiceIndex < 0 || choiceIndex >= this.data.choices.length) {
46
+ logger.error(`Choice index ${choiceIndex} is out of bounds.`);
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=openai-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-response.js","sourceRoot":"","sources":["../../src/openai/openai-response.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,MAAM,GAAG,YAAY,CAAC;IAC1B,OAAO,EAAE,YAAY;IACrB,cAAc,EAAE,iBAAiB;CAClC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,OAAO,4BAA4B;IAKX;IAJ5B;;OAEG;IACa,IAAI,CAA6B;IACjD,YAA4B,WAAyB;QAAzB,gBAAW,GAAX,WAAW,CAAc;QACnD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,WAAW,GAAG,CAAC;QAC7B,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,aAAa,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,WAAW,GAAG,CAAC;QACxB,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC;IAC1D,CAAC;IAEO,qBAAqB,CAAC,WAAmB;QAC/C,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAC/D,MAAM,CAAC,KAAK,CAAC,gBAAgB,WAAW,oBAAoB,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,527 @@
1
+ /**
2
+ * Available OpenAI models for chat completion.
3
+ */
4
+ export type OpenAiChatModel = 'gpt-4o' | 'gpt-4' | 'gpt-4-32k' | 'gpt-35-turbo' | 'gpt-35-turbo-0125' | 'gpt-35-turbo-16k';
5
+ /**
6
+ * OpenAI embedding models.
7
+ */
8
+ export type OpenAiEmbeddingModel = 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large';
9
+ /**
10
+ * OpenAI system message.
11
+ */
12
+ export interface OpenAiChatSystemMessage {
13
+ /**
14
+ * The role of the messages author,.
15
+ */
16
+ role: 'system';
17
+ /**
18
+ * An optional name for the participant. Provides the model information to differentiate between participants of the same role.
19
+ */
20
+ name?: string;
21
+ /**
22
+ * The contents of the system message.
23
+ */
24
+ content: string;
25
+ }
26
+ /**
27
+ * OpenAI user message.
28
+ */
29
+ export interface OpenAiChatUserMessage {
30
+ /**
31
+ * The role of the messages author,.
32
+ */
33
+ role: 'user';
34
+ /**
35
+ * An optional name for the participant. Provides the model information to differentiate between participants of the same role.
36
+ */
37
+ name?: string;
38
+ /**
39
+ * The contents of the user message.
40
+ */
41
+ content: string | ({
42
+ /**
43
+ * The type of the content part.
44
+ */
45
+ type: 'text';
46
+ /**
47
+ * The text content.
48
+ */
49
+ text: string;
50
+ } | {
51
+ /**
52
+ * The type of the content part.
53
+ */
54
+ type: 'image_url';
55
+ image_url: string | {
56
+ /**
57
+ * Either a URL of the image or the base64 encoded image data.
58
+ */
59
+ url: string;
60
+ /**
61
+ * Specifies the detail level of the image.
62
+ * @default auto
63
+ */
64
+ detail?: 'auto' | 'low' | 'high';
65
+ };
66
+ })[];
67
+ }
68
+ /**
69
+ * OpenAI assistant message.
70
+ */
71
+ export interface OpenAiChatAssistantMessage {
72
+ /**
73
+ * The role of the messages author,.
74
+ */
75
+ role: 'assistant';
76
+ /**
77
+ * An optional name for the participant. Provides the model information to differentiate between participants of the same role.
78
+ */
79
+ name?: string;
80
+ /**
81
+ * Message content.
82
+ */
83
+ content?: string;
84
+ /**
85
+ * Function which is called.
86
+ * @deprecated In favor of `tool_calls`.
87
+ */
88
+ function_call?: OpenAiChatFunctionCall;
89
+ /**
90
+ * The tool calls generated by the model, such as function calls.
91
+ */
92
+ tool_calls?: OpenAiChatToolCall[];
93
+ }
94
+ /**
95
+ * OpenAI tool message.
96
+ */
97
+ export interface OpenAiChatToolMessage {
98
+ /**
99
+ * The role of the messages author,.
100
+ */
101
+ role: 'tool';
102
+ /**
103
+ * The contents of the tool message.
104
+ */
105
+ content: string;
106
+ /**
107
+ * Tool call that this message is responding to.
108
+ */
109
+ tool_call_id: string;
110
+ }
111
+ /**
112
+ * OpenAI function message.
113
+ */
114
+ export interface OpenAiChatFunctionMessage {
115
+ /**
116
+ * The role of the messages author,.
117
+ */
118
+ role: 'function';
119
+ /**
120
+ * The contents of the function message.
121
+ */
122
+ content: string | null;
123
+ /**
124
+ * The name of the function to call.
125
+ */
126
+ name: string;
127
+ }
128
+ /**
129
+ * OpenAI chat message types.
130
+ */
131
+ export type OpenAiChatMessage = OpenAiChatSystemMessage | OpenAiChatUserMessage | OpenAiChatAssistantMessage | OpenAiChatToolMessage | OpenAiChatFunctionMessage;
132
+ /**
133
+ * OpenAI function signature.
134
+ */
135
+ export interface OpenAiChatCompletionFunction {
136
+ /**
137
+ * Name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
138
+ */
139
+ name: string;
140
+ /**
141
+ * Description of the function.
142
+ */
143
+ description?: string;
144
+ /**
145
+ * JSON Schema for the function input parameters.
146
+ *
147
+ * **Note**: As mentioned in {@link https://community.openai.com/t/whitch-json-schema-version-should-function-calling-use/283535/4}, it follows JSON Schema 7 (2020-12).
148
+ * Not all JSON Schema parameters in the specification are supported by OpenAI.
149
+ */
150
+ parameters: Record<string, unknown>;
151
+ }
152
+ /**
153
+ * OpenAI tool signature.
154
+ */
155
+ export interface OpenAiChatCompletionTool {
156
+ /**
157
+ * The type of the tool.
158
+ */
159
+ type: 'function';
160
+ /**
161
+ * Function signature.
162
+ */
163
+ function: OpenAiChatCompletionFunction;
164
+ }
165
+ /**
166
+ * OpenAI function call by AI.
167
+ */
168
+ export interface OpenAiChatFunctionCall {
169
+ /**
170
+ * Name of the function call.
171
+ */
172
+ name: string;
173
+ /**
174
+ * The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
175
+ */
176
+ arguments: string;
177
+ }
178
+ /**
179
+ * OpenAI tool call by AI.
180
+ */
181
+ export interface OpenAiChatToolCall {
182
+ /**
183
+ * The ID of the tool call.
184
+ */
185
+ id: string;
186
+ /**
187
+ * The type of the tool.
188
+ */
189
+ type: 'function';
190
+ /**
191
+ * The function that the model called.
192
+ */
193
+ function: OpenAiChatFunctionCall;
194
+ }
195
+ /**
196
+ * OpenAI completion input parameters.
197
+ */
198
+ export interface OpenAiCompletionParameters {
199
+ /**
200
+ * The maximum number of [tokens](/tokenizer) that can be generated in the completion. The token count of your prompt plus max_tokens can't exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).
201
+ */
202
+ max_tokens?: number;
203
+ /**
204
+ * What sampling temperature to use, between 0 and 2. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (`argmax sampling`) for ones with a well-defined answer. We generally recommend altering this or top_p but not both.
205
+ */
206
+ temperature?: number;
207
+ /**
208
+ * An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
209
+ */
210
+ top_p?: number;
211
+ /**
212
+ * Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token. As an example, you can pass {"50256": -100} to prevent the <|endoftext|> token from being generated.
213
+ */
214
+ logit_bias?: Record<string, unknown>;
215
+ /**
216
+ * A unique identifier representing your end-user, which can help monitoring and detecting abuse.
217
+ */
218
+ user?: string;
219
+ /**
220
+ * How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.
221
+ */
222
+ n?: number;
223
+ /**
224
+ * Up to four sequences where the API will stop generating further tokens. The returned text won't contain the stop sequence.
225
+ */
226
+ stop?: string | string[];
227
+ /**
228
+ * Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
229
+ */
230
+ presence_penalty?: number;
231
+ /**
232
+ * Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
233
+ */
234
+ frequency_penalty?: number;
235
+ }
236
+ /**
237
+ * OpenAI chat completion input parameters.
238
+ */
239
+ export interface OpenAiChatCompletionParameters extends OpenAiCompletionParameters {
240
+ /**
241
+ * An array of system, user & assistant messages for chat completion.
242
+ */
243
+ messages: OpenAiChatMessage[];
244
+ /**
245
+ * An object specifying the format that the model must output. Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.
246
+ *
247
+ * **Important**: when using JSON mode, you *must* also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly "stuck" request. Also note that the message content may be partially cut off if `finish_reason="length"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.
248
+ */
249
+ response_format?: {
250
+ /**
251
+ * Type of response format.
252
+ * @default text
253
+ */
254
+ type: 'text' | 'json_object';
255
+ };
256
+ /**
257
+ * If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result. Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
258
+ */
259
+ seed?: number;
260
+ /**
261
+ * Array of function signatures to be called.
262
+ * @deprecated Use `tools` instead.
263
+ */
264
+ functions?: OpenAiChatCompletionFunction[];
265
+ /**
266
+ * A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
267
+ */
268
+ tools?: OpenAiChatCompletionTool[];
269
+ /**
270
+ * Controls which (if any) function is called by the model.
271
+ *
272
+ * - `none` means the model will not call a function and instead generates a message.
273
+ * - `auto` means the model can pick between generating a message or calling a function.
274
+ * - Specifying a particular function via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that function.
275
+ */
276
+ tool_choice?: 'none' | 'auto' | {
277
+ /**
278
+ * The type of the tool.
279
+ */
280
+ type: 'function';
281
+ /**
282
+ * Use to force the model to call a specific function.
283
+ */
284
+ function: {
285
+ /**
286
+ * The name of the function to call.
287
+ */
288
+ name: string;
289
+ };
290
+ };
291
+ }
292
+ /**
293
+ * OpenAI embedding input parameters.
294
+ */
295
+ export interface OpenAiEmbeddingParameters {
296
+ /**
297
+ * Input text to get embeddings for, encoded as a string. The number of input tokens varies depending on what model you are using. Unless you're embedding code, we suggest replacing newlines (\n) in your input with a single space, as we have observed inferior results when newlines are present.
298
+ */
299
+ input: string[] | string;
300
+ /**
301
+ * A unique identifier representing for your end-user. This will help Azure OpenAI monitor and detect abuse. Do not pass PII identifiers instead use pseudoanonymized values such as GUIDs.
302
+ */
303
+ user?: string;
304
+ }
305
+ /**
306
+ * Usage statistics for the completion request.
307
+ */
308
+ export interface OpenAiUsage {
309
+ /**
310
+ * Tokens consumed for output text completion.
311
+ */
312
+ completion_tokens: number;
313
+ /**
314
+ * Tokens consumed for input prompt tokens.
315
+ */
316
+ prompt_tokens: number;
317
+ /**
318
+ * Total tokens consumed for input + output.
319
+ */
320
+ total_tokens: number;
321
+ }
322
+ /**
323
+ * OpenAI completion output .
324
+ */
325
+ export interface OpenAiCompletionOutput {
326
+ /**
327
+ *
328
+ */
329
+ created: number;
330
+ /**
331
+ * Unique ID for completion.
332
+ */
333
+ id: string;
334
+ /**
335
+ * Name of the model used for completion.
336
+ */
337
+ model: string;
338
+ /**
339
+ * Completion object.
340
+ */
341
+ object: 'chat.completion' | 'text_completion';
342
+ /**
343
+ * Token usage.
344
+ */
345
+ usage: OpenAiUsage;
346
+ /**
347
+ * Content filtering results for zero or more prompts in the request.
348
+ */
349
+ prompt_filter_results?: OpenAiPromptFilterResult[];
350
+ }
351
+ /**
352
+ * OpenAI chat completion output.
353
+ */
354
+ export interface OpenAiChatCompletionOutput extends OpenAiCompletionOutput {
355
+ /**
356
+ * Array of result candidates.
357
+ */
358
+ choices: OpenAiChatCompletionChoice[];
359
+ /**
360
+ * This fingerprint represents the backend configuration that the model runs with.
361
+ * Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
362
+ */
363
+ system_fingerprint: string;
364
+ }
365
+ /**
366
+ * Content filtering results for a single prompt in the request.
367
+ */
368
+ export interface OpenAiPromptFilterResult {
369
+ /**
370
+ * Index of the prompt in the request.
371
+ */
372
+ prompt_index?: number;
373
+ /**
374
+ * Information about the content filtering category, if it has been detected, as well as the severity level and if it has been filtered or not.
375
+ */
376
+ content_filter_results?: OpenAiContentFilterPromptResults;
377
+ }
378
+ /**
379
+ * OpenAI completion choice.
380
+ */
381
+ export interface OpenAiCompletionChoice {
382
+ /**
383
+ * Reason for finish.
384
+ */
385
+ finish_reason?: string;
386
+ /**
387
+ * Index of choice.
388
+ */
389
+ index: number;
390
+ /**
391
+ * Information about the content filtering category, if it has been detected, as well as the severity level and if it has been filtered or not.
392
+ */
393
+ content_filter_results?: OpenAiContentFilterPromptResults;
394
+ }
395
+ /**
396
+ * OpenAI chat completion choice.
397
+ */
398
+ export interface OpenAiChatCompletionChoice extends OpenAiCompletionChoice {
399
+ /**
400
+ * Completion chat message.
401
+ */
402
+ message: OpenAiChatAssistantMessage;
403
+ }
404
+ /**
405
+ * Information about the content filtering results.
406
+ */
407
+ export interface OpenAiContentFilterResultsBase {
408
+ /**
409
+ * Sexual content filter result.
410
+ */
411
+ sexual?: OpenAiContentFilterSeverityResult;
412
+ /**
413
+ * Violent content filter result.
414
+ */
415
+ violence?: OpenAiContentFilterSeverityResult;
416
+ /**
417
+ * Hate speech content filter result.
418
+ */
419
+ hate?: OpenAiContentFilterSeverityResult;
420
+ /**
421
+ * Intolerant content filter result.
422
+ */
423
+ selfHarm?: OpenAiContentFilterSeverityResult;
424
+ /**
425
+ * Profanity content filter result.
426
+ */
427
+ profanity?: OpenAiContentFilterDetectedResult;
428
+ /**
429
+ * Error.
430
+ */
431
+ error?: OpenAiErrorBase;
432
+ }
433
+ /**
434
+ * Content filtering results for a prompt in the request.
435
+ */
436
+ export interface OpenAiContentFilterPromptResults extends OpenAiContentFilterResultsBase {
437
+ /**
438
+ *
439
+ */
440
+ jailbreak?: OpenAiContentFilterDetectedResult;
441
+ }
442
+ /**
443
+ * OpenAI content filter result.
444
+ */
445
+ export interface OpenAiContentFilterResultBase {
446
+ /**
447
+ * Whether the content was filtered.
448
+ */
449
+ filtered: boolean;
450
+ }
451
+ /**
452
+ * OpenAI content filter detected result.
453
+ */
454
+ export interface OpenAiContentFilterDetectedResult extends OpenAiContentFilterResultBase {
455
+ /**
456
+ * Whether the content was detected.
457
+ */
458
+ detected: boolean;
459
+ }
460
+ /**
461
+ * OpenAI error.
462
+ */
463
+ export interface OpenAiErrorBase {
464
+ /**
465
+ * Error code.
466
+ */
467
+ code?: string;
468
+ /**
469
+ * Error message.
470
+ */
471
+ message?: string;
472
+ }
473
+ /**
474
+ * Information about the content filtering results.
475
+ */
476
+ export interface OpenAiContentFilterSeverityResult extends OpenAiContentFilterResultBase {
477
+ /**
478
+ * Severity of the content.
479
+ */
480
+ severity: 'safe' | 'low' | 'medium' | 'high';
481
+ }
482
+ /**
483
+ * OpenAI embedding output.
484
+ */
485
+ export interface OpenAiEmbeddingOutput {
486
+ /**
487
+ * List object.
488
+ */
489
+ object: 'list';
490
+ /**
491
+ * Model used for embedding.
492
+ */
493
+ model: string;
494
+ /**
495
+ * Array of result candidates.
496
+ */
497
+ data: [
498
+ {
499
+ /**
500
+ * Embedding object.
501
+ */
502
+ object: 'embedding';
503
+ /**
504
+ * Array of size `1536` (OpenAI's embedding size) containing embedding vector.
505
+ */
506
+ embedding: number[];
507
+ /**
508
+ * Index of choice.
509
+ */
510
+ index: number;
511
+ }
512
+ ];
513
+ /**
514
+ * Token Usage.
515
+ */
516
+ usage: {
517
+ /**
518
+ * Tokens consumed for input prompt tokens.
519
+ */
520
+ prompt_tokens: number;
521
+ /**
522
+ * Total tokens consumed.
523
+ */
524
+ total_tokens: number;
525
+ };
526
+ }
527
+ //# sourceMappingURL=openai-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-types.d.ts","sourceRoot":"","sources":["../../src/openai/openai-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,OAAO,GACP,WAAW,GACX,cAAc,GACd,mBAAmB,GACnB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B,wBAAwB,GACxB,wBAAwB,GACxB,wBAAwB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC;IACf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EACH,MAAM,GACN,CACI;QACE;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QACb;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;KACd,GACD;QACE;;WAEG;QACH,IAAI,EAAE,WAAW,CAAC;QAClB,SAAS,EACL,MAAM,GACN;YACE;;eAEG;YACH,GAAG,EA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ACH,IAAI,EAAE;QACJ;YACE;;eAEG;YACH,MAAM,EAAE,WAAW,CAAC;YACpB;;eAEG;YACH,SAAS,EAAE,MAAM,EAAE,CAAC;YACpB;;eAEG;YACH,KAAK,EAAE,MAAM,CAAC;SACf;KACF,CAAC;IACF;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,aAAa,EAAE,MAAM,CAAC;QACtB;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=openai-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-types.js","sourceRoot":"","sources":["../../src/openai/openai-types.ts"],"names":[],"mappings":""}
package/internal.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // eslint-disable-next-line import/no-internal-modules
2
+ export * from './dist/internal.js';
3
+ // # sourceMappingURL=internal.d.ts.map
package/internal.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/internal.js';
2
+ //# sourceMappingURL=internal.js.map
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@sap-ai-sdk/foundation-models",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "license": "Apache-2.0",
6
+ "keywords": [
7
+ "sap-ai-sdk",
8
+ "foundation-models",
9
+ "llm-access"
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
+ "dependencies": {
23
+ "@sap-cloud-sdk/http-client": "^3.20.0",
24
+ "@sap-cloud-sdk/connectivity": "^3.20.0",
25
+ "@sap-cloud-sdk/util": "^3.20.0",
26
+ "@sap-cloud-sdk/openapi": "^3.20.0",
27
+ "@sap-ai-sdk/core": "^0.1.0",
28
+ "@sap-ai-sdk/ai-api": "^0.1.0"
29
+ },
30
+ "devDependencies": {
31
+ "@sap-cloud-sdk/openapi-generator": "^3.20.0",
32
+ "typescript": "^5.5.4",
33
+ "nock": "^13.5.5"
34
+ },
35
+ "scripts": {
36
+ "compile": "tsc",
37
+ "compile:cjs": "tsc -p tsconfig.cjs.json",
38
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
39
+ "lint": "eslint \"**/*.ts\" && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -c",
40
+ "lint:fix": "eslint \"**/*.ts\" --fix && prettier . --config ../../.prettierrc --ignore-path ../../.prettierignore -w --log-level error",
41
+ "check:public-api": "node --loader ts-node/esm ../../scripts/check-public-api-cli.ts"
42
+ }
43
+ }