公众号验证码功能完成 yeah!!!
This commit is contained in:
44
node_modules/openai/azure.mjs
generated
vendored
44
node_modules/openai/azure.mjs
generated
vendored
@@ -1,7 +1,7 @@
|
||||
import { buildHeaders } from "./internal/headers.mjs";
|
||||
import * as Errors from "./error.mjs";
|
||||
import { isObj, readEnv } from "./internal/utils.mjs";
|
||||
import { OpenAI } from "./client.mjs";
|
||||
import { buildHeaders } from "./internal/headers.mjs";
|
||||
/** API Client for interfacing with the Azure OpenAI API. */
|
||||
export class AzureOpenAI extends OpenAI {
|
||||
/**
|
||||
@@ -34,8 +34,6 @@ export class AzureOpenAI extends OpenAI {
|
||||
if (azureADTokenProvider && apiKey) {
|
||||
throw new Errors.OpenAIError('The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.');
|
||||
}
|
||||
// define a sentinel value to avoid any typing issues
|
||||
apiKey ?? (apiKey = API_KEY_SENTINEL);
|
||||
opts.defaultQuery = { ...opts.defaultQuery, 'api-version': apiVersion };
|
||||
if (!baseURL) {
|
||||
if (!endpoint) {
|
||||
@@ -52,13 +50,12 @@ export class AzureOpenAI extends OpenAI {
|
||||
}
|
||||
}
|
||||
super({
|
||||
apiKey,
|
||||
apiKey: azureADTokenProvider ?? apiKey,
|
||||
baseURL,
|
||||
...opts,
|
||||
...(dangerouslyAllowBrowser !== undefined ? { dangerouslyAllowBrowser } : {}),
|
||||
});
|
||||
this.apiVersion = '';
|
||||
this._azureADTokenProvider = azureADTokenProvider;
|
||||
this.apiVersion = apiVersion;
|
||||
this.deploymentName = deployment;
|
||||
}
|
||||
@@ -74,41 +71,11 @@ export class AzureOpenAI extends OpenAI {
|
||||
}
|
||||
return super.buildRequest(options, props);
|
||||
}
|
||||
async _getAzureADToken() {
|
||||
if (typeof this._azureADTokenProvider === 'function') {
|
||||
const token = await this._azureADTokenProvider();
|
||||
if (!token || typeof token !== 'string') {
|
||||
throw new Errors.OpenAIError(`Expected 'azureADTokenProvider' argument to return a string but it returned ${token}`);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
async authHeaders(opts) {
|
||||
return;
|
||||
}
|
||||
async prepareOptions(opts) {
|
||||
opts.headers = buildHeaders([opts.headers]);
|
||||
/**
|
||||
* The user should provide a bearer token provider if they want
|
||||
* to use Azure AD authentication. The user shouldn't set the
|
||||
* Authorization header manually because the header is overwritten
|
||||
* with the Azure AD token if a bearer token provider is provided.
|
||||
*/
|
||||
if (opts.headers.values.get('Authorization') || opts.headers.values.get('api-key')) {
|
||||
return super.prepareOptions(opts);
|
||||
if (typeof this._options.apiKey === 'string') {
|
||||
return buildHeaders([{ 'api-key': this.apiKey }]);
|
||||
}
|
||||
const token = await this._getAzureADToken();
|
||||
if (token) {
|
||||
opts.headers.values.set('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
else if (this.apiKey !== API_KEY_SENTINEL) {
|
||||
opts.headers.values.set('api-key', this.apiKey);
|
||||
}
|
||||
else {
|
||||
throw new Errors.OpenAIError('Unable to handle auth');
|
||||
}
|
||||
return super.prepareOptions(opts);
|
||||
return super.authHeaders(opts);
|
||||
}
|
||||
}
|
||||
const _deployments_endpoints = new Set([
|
||||
@@ -122,5 +89,4 @@ const _deployments_endpoints = new Set([
|
||||
'/batches',
|
||||
'/images/edits',
|
||||
]);
|
||||
const API_KEY_SENTINEL = '<Missing Key>';
|
||||
//# sourceMappingURL=azure.mjs.map
|
||||
Reference in New Issue
Block a user