feat(OpenAIClient): AZURE_USE_MODEL_AS_DEPLOYMENT_NAME, AZURE_OPENAI_DEFAULT_MODEL (#1165)

* feat(OpenAIClient): AZURE_USE_MODEL_AS_DEPLOYMENT_NAME, AZURE_OPENAI_DEFAULT_MODEL

* ci: fix initializeClient test
This commit is contained in:
Danny Avila 2023-11-10 09:58:17 -05:00 committed by GitHub
parent 9d100ec0fc
commit d5259e1525
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 242 additions and 60 deletions

View file

@ -43,7 +43,12 @@ describe('gptPlugins/initializeClient', () => {
test('should initialize PluginsClient with Azure credentials when PLUGINS_USE_AZURE is true', async () => {
process.env.AZURE_API_KEY = 'test-azure-api-key';
process.env.PLUGINS_USE_AZURE = 'true';
(process.env.AZURE_OPENAI_API_INSTANCE_NAME = 'some-value'),
(process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME = 'some-value'),
(process.env.AZURE_OPENAI_API_VERSION = 'some-value'),
(process.env.AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME = 'some-value'),
(process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME = 'some-value'),
(process.env.PLUGINS_USE_AZURE = 'true');
process.env.DEBUG_PLUGINS = 'false';
process.env.OPENAI_SUMMARIZE = 'false';
@ -174,31 +179,6 @@ describe('gptPlugins/initializeClient', () => {
);
});
test('should sanitize model name for Azure when modelOptions is provided', async () => {
process.env.AZURE_API_KEY = 'azure-provided-api-key';
process.env.PLUGINS_USE_AZURE = 'true';
const modelName = 'test-3.5-model';
const sanitizedModelName = 'test-35-model';
const req = {
body: { key: new Date(Date.now() + 10000).toISOString() },
user: { id: '123' },
};
const res = {};
const endpointOption = { modelOptions: { model: modelName } };
getUserKey.mockResolvedValue(
JSON.stringify({
azureOpenAIApiKey: 'test-user-provided-azure-api-key',
azureOpenAIApiDeploymentName: modelName,
}),
);
const { azure } = await initializeClient({ req, res, endpointOption });
expect(azure.azureOpenAIApiDeploymentName).toBe(sanitizedModelName);
});
test('should throw an error if the user-provided Azure key is invalid JSON', async () => {
process.env.AZURE_API_KEY = 'user_provided';
process.env.PLUGINS_USE_AZURE = 'true';