UNPKG

@microsoft/botbuilder-m365

Version:

M365 extensions for Microsoft BotBuilder, Alpha release.

73 lines 2.89 kB
"use strict"; /** * @module botbuilder-m365 */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AzureOpenAIClient = void 0; const OpenAIClient_1 = require("./OpenAIClient"); /** * `AzureOpenAIClient` Allows for Azure hosted OpenAI clients to be created and used. As of 4/4/2023, access keys must be specifically assigned to be used with this client. */ class AzureOpenAIClient extends OpenAIClient_1.OpenAIClient { constructor(options) { super(options); // Validate endpoint if (!options.endpoint) { throw new Error(`AzureOpenAIClient initialized without an 'endpoint'.`); } } createCompletion(request) { var _a; const clone = Object.assign({}, request); const deployment = this.removeModel(clone); const endpoint = this.options.endpoint; const apiVersion = (_a = this.options.apiVersion) !== null && _a !== void 0 ? _a : '2022-12-01'; const url = `${endpoint}/openai/deployments/${deployment}/completions?api-version=${apiVersion}`; return this.post(url, clone); } createChatCompletion(request) { var _a; const clone = Object.assign({}, request); const deployment = this.removeModel(clone); const endpoint = this.options.endpoint; const apiVersion = (_a = this.options.apiVersion) !== null && _a !== void 0 ? _a : '2023-03-15-preview'; const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`; return this.post(url, clone); } createEmbedding(request) { var _a; const clone = Object.assign({}, request); const deployment = this.removeModel(clone); const endpoint = this.options.endpoint; const apiVersion = (_a = this.options.apiVersion) !== null && _a !== void 0 ? _a : '2022-12-01'; const url = `${endpoint}/openai/deployments/${deployment}/embeddings?api-version=${apiVersion}`; return this.post(url, clone); } /** * Placeholder for future implementation. * * @param {CreateModerationRequest} request The input request and model payload. */ createModeration(request) { throw new Error(`the AzureOpenAIClient does not currently support calling the Moderation API.`); } addRequestHeaders(headers, options) { headers['api-key'] = options.apiKey; } removeModel(request) { const model = request.model; delete request.model; if (model) { return model; } else { return ''; } } } exports.AzureOpenAIClient = AzureOpenAIClient; //# sourceMappingURL=AzureOpenAIClient.js.map