@microsoft/teams-ai
Version:
SDK focused on building AI based applications for Microsoft Teams.
55 lines • 2.17 kB
JavaScript
;
/**
* @module teams-ai
*/
/**
* 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");
/**
* @private
* @class
* @implements {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'.`);
}
}
createChatCompletion(request) {
const clone = Object.assign({}, request);
const deployment = request.model;
const endpoint = this.options.endpoint;
const apiVersion = this.options.apiVersion ?? '2024-02-15-preview';
const url = `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
return this.post(url, clone);
}
createEmbedding(request) {
const clone = Object.assign({}, request);
const deployment = request.model;
const endpoint = this.options.endpoint;
const apiVersion = this.options.apiVersion ?? '2022-12-01';
const url = `${endpoint}/openai/deployments/${deployment}/embeddings?api-version=${apiVersion}`;
return this.post(url, clone);
}
createModeration(request) {
const endpoint = this.options.endpoint;
const url = `${endpoint}/contentsafety/text:analyze?api-version=${this.options.apiVersion}`;
return this.post(url, request);
}
addRequestHeaders(headers, options) {
headers[options.headerKey ?? 'api-key'] = options.apiKey;
if (options.ocpApimSubscriptionKey) {
headers['Ocp-Apim-Subscription-Key'] = options.ocpApimSubscriptionKey;
}
}
}
exports.AzureOpenAIClient = AzureOpenAIClient;
//# sourceMappingURL=AzureOpenAIClient.js.map