UNPKG

@sap-ai-sdk/foundation-models

Version:

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.

48 lines 1.52 kB
import { createLogger, pickValueIgnoreCase } from '@sap-cloud-sdk/util'; const logger = createLogger({ package: 'foundation-models', messageContext: 'azure-openai-embedding-response' }); /** * Azure OpenAI embedding response. */ export class AzureOpenAiEmbeddingResponse { rawResponse; /** * The embedding response. */ _data; constructor(rawResponse) { this.rawResponse = rawResponse; this._data = rawResponse.data; } /** * Gets the request ID from the response headers. * @returns The request ID, or undefined if the header is not present. */ getRequestId() { return pickValueIgnoreCase(this.rawResponse.headers, 'x-aicore-request-id'); } /** * Parses the Azure OpenAI response and returns the embedding. * @param dataIndex - The index of the data to parse. * @returns The embedding vector. */ getEmbedding(dataIndex = 0) { this.logInvalidDataIndex(dataIndex); return this._data.data[dataIndex]?.embedding; } /** * Parses the Azure OpenAI response and returns all embeddings. * @returns The embedding vectors. */ getEmbeddings() { return this._data.data.map(({ embedding }) => embedding); } logInvalidDataIndex(dataIndex) { if (dataIndex < 0 || dataIndex >= this._data.data.length) { logger.error(`Data index ${dataIndex} is out of bounds.`); } } } //# sourceMappingURL=azure-openai-embedding-response.js.map