|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +import { TokenCredential, KeyCredential } from "@azure/core-auth"; |
| 5 | +import { ClientOptions, Client, getClient } from "@azure-rest/core-client"; |
| 6 | +import { logger } from "../logger.js"; |
| 7 | + |
| 8 | +export interface AssistantsContext extends Client {} |
| 9 | + |
| 10 | +/** Optional parameters for the client. */ |
| 11 | +export interface AssistantsClientOptionalParams extends ClientOptions {} |
| 12 | + |
| 13 | +/** Azure OpenAI APIs for Assistants. */ |
| 14 | +export function createAssistants( |
| 15 | + endpointParam: string, |
| 16 | + credential: KeyCredential | TokenCredential, |
| 17 | + options: AssistantsClientOptionalParams = {}, |
| 18 | +): AssistantsContext { |
| 19 | + const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`; |
| 20 | + |
| 21 | + const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; |
| 22 | + const userAgentPrefix = prefixFromOptions |
| 23 | + ? `${prefixFromOptions} azsdk-js-api` |
| 24 | + : "azsdk-js-api"; |
| 25 | + const { apiVersion: _, ...updatedOptions } = { |
| 26 | + ...options, |
| 27 | + userAgentOptions: { userAgentPrefix }, |
| 28 | + loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info }, |
| 29 | + credentials: { |
| 30 | + scopes: options.credentials?.scopes ?? [ |
| 31 | + "https://cognitiveservices.azure.com/.default", |
| 32 | + ], |
| 33 | + apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "api-key", |
| 34 | + }, |
| 35 | + }; |
| 36 | + const clientContext = getClient(endpointUrl, credential, updatedOptions); |
| 37 | + clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" }); |
| 38 | + if (options.apiVersion) { |
| 39 | + logger.warning( |
| 40 | + "This client does not support client api-version, please change it at the operation level", |
| 41 | + ); |
| 42 | + } |
| 43 | + return clientContext; |
| 44 | +} |
0 commit comments