@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**.
39 lines • 1.11 kB
JavaScript
/**
* Azure OpenAI chat completion response.
*/
export class AzureOpenAiChatCompletionResponse {
rawResponse;
/**
* The chat completion response.
*/
data;
constructor(rawResponse) {
this.rawResponse = rawResponse;
this.data = rawResponse.data;
}
/**
* Usage of tokens in the response.
* @returns Token usage.
*/
getTokenUsage() {
return this.data.usage;
}
/**
* Reason for stopping the completion.
* @param choiceIndex - The index of the choice to parse.
* @returns The finish reason.
*/
getFinishReason(choiceIndex = 0) {
return this.data.choices.find(c => c.index === choiceIndex)?.finish_reason;
}
/**
* Parses the Azure OpenAI response and returns the content.
* @param choiceIndex - The index of the choice to parse.
* @returns The message content.
*/
getContent(choiceIndex = 0) {
return this.data.choices.find(c => c.index === choiceIndex)?.message
?.content;
}
}
//# sourceMappingURL=azure-openai-chat-completion-response.js.map