Skip to content

Commit ecb298f

Browse files
qinzhouxuwh-alice
andauthored
Merge pull request #14198 from OfficeDev/qinzhouxu/env (#14224)
fix: support more alerts of environment variables Co-authored-by: Alice Wang <[email protected]>
1 parent 2fbc60e commit ecb298f

File tree

7 files changed

+426
-1
lines changed

7 files changed

+426
-1
lines changed

packages/fx-core/resource/package.nls.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@
416416
"core.createProjectQuestion.llmService.azureOpenAIDeploymentName.title": "Azure OpenAI Deployment Name",
417417
"core.createProjectQuestion.llmService.azureOpenAIEndpoint.placeholder": "Input Azure OpenAI service endpoint now or set it later in the project",
418418
"core.createProjectQuestion.llmService.azureOpenAIDeploymentName.placeholder": "Input Azure OpenAI deployment name now or set it later in the project",
419+
"core.createProjectQuestion.llmService.openAIAssistantID.title": "OpenAI Assistant ID",
420+
"core.createProjectQuestion.llmService.openAIAssistantID.placeholder": "Enter OpenAI Assistant ID now or set it later in the project",
421+
"core.createProjectQuestion.llmService.azureOpenAIAssistantID.title": "Azure OpenAI Assistant ID",
422+
"core.createProjectQuestion.llmService.azureOpenAIAssistantID.placeholder": "Enter Azure OpenAI Assistant ID now or set it later in the project",
423+
"core.createProjectQuestion.llmService.azureOpenAIEmbeddingDeploymentName.title": "Azure OpenAI Embedding Deployment Name",
424+
"core.createProjectQuestion.llmService.azureOpenAIEmbeddingDeploymentName.placeholder": "Enter Azure OpenAI embedding deployment name now or set it later in the project",
419425
"core.createProjectQuestion.apiPlugin.importPlugin.label": "Import from an Existing Action",
420426
"core.createProjectQuestion.apiPlugin.importPlugin.detail": "Import from an existing action file",
421427
"core.createProjectQuestion.apiSpec.title": "OpenAPI Description Document",
@@ -845,6 +851,8 @@
845851
"driver.file.createOrUpdateEnvironmentFile.OpenAIKey.validation": "OpenAI key cannot be empty.",
846852
"driver.file.createOrUpdateEnvironmentFile.OpenAIDeploymentEndpoint.validation": "Azure OpenAI endpoint must be a valid URL.",
847853
"driver.file.createOrUpdateEnvironmentFile.OpenAIDeploymentName.validation": "Azure OpenAI deployment name cannot be empty.",
854+
"driver.file.createOrUpdateEnvironmentFile.OpenAIAssistantID.validation": "OpenAI assistant ID cannot be empty.",
855+
"driver.file.createOrUpdateEnvironmentFile.OpenAIEmbeddingDeploymentName.validation": "Azure OpenAI embedding deployment name cannot be empty.",
848856
"driver.file.createOrUpdateJsonFile.description": "Create or update JSON file.",
849857
"driver.file.createOrUpdateJsonFile.summary": "Json file has been successfully generated to %s.",
850858
"driver.file.progressBar.appsettings": "Generating json file...",

packages/fx-core/src/component/configManager/lifecycle.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ export function resolveString(
106106
envVar === OpenAIEnvironmentVariables.SECRET_AZURE_OPENAI_API_KEY ||
107107
envVar === OpenAIEnvironmentVariables.AZURE_OPENAI_ENDPOINT ||
108108
envVar === OpenAIEnvironmentVariables.AZURE_OPENAI_DEPLOYMENT_NAME ||
109-
envVar === OpenAIEnvironmentVariables.SECRET_OPENAI_API_KEY
109+
envVar === OpenAIEnvironmentVariables.SECRET_OPENAI_API_KEY ||
110+
envVar === OpenAIEnvironmentVariables.AZURE_OPENAI_MODEL_DEPLOYMENT_NAME ||
111+
envVar === OpenAIEnvironmentVariables.OPENAI_ASSISTANT_ID ||
112+
envVar === OpenAIEnvironmentVariables.AZURE_OPENAI_ASSISTANT_ID ||
113+
envVar === OpenAIEnvironmentVariables.AZURE_OPENAI_EMBEDDING_DEPLOYMENT
110114
) {
111115
if (envVal) {
112116
resolved.push(envVar);

packages/fx-core/src/component/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,8 @@ export const OpenAIEnvironmentVariables = {
124124
SECRET_AZURE_OPENAI_API_KEY: "SECRET_AZURE_OPENAI_API_KEY",
125125
AZURE_OPENAI_ENDPOINT: "AZURE_OPENAI_ENDPOINT",
126126
AZURE_OPENAI_DEPLOYMENT_NAME: "AZURE_OPENAI_DEPLOYMENT_NAME",
127+
AZURE_OPENAI_MODEL_DEPLOYMENT_NAME: "AZURE_OPENAI_MODEL_DEPLOYMENT_NAME",
128+
OPENAI_ASSISTANT_ID: "OPENAI_ASSISTANT_ID",
129+
AZURE_OPENAI_ASSISTANT_ID: "AZURE_OPENAI_ASSISTANT_ID",
130+
AZURE_OPENAI_EMBEDDING_DEPLOYMENT: "AZURE_OPENAI_EMBEDDING_DEPLOYMENT",
127131
};

packages/fx-core/src/component/driver/file/createOrUpdateEnvironmentFile.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import { Service } from "typedi";
1111
import { getLocalizedString } from "../../../common/localizeUtils";
1212
import { InvalidActionInputError, assembleError } from "../../../error/common";
1313
import {
14+
azureOpenAIAssistantIdQuestion,
1415
azureOpenAIDeploymentNameQuestion,
16+
azureOpenAIEmbeddingDeploymentNameQuestion,
1517
azureOpenAIEndpointQuestion,
1618
azureOpenAIKeyQuestion,
19+
openAIAssistantIdQuestion,
1720
openAIKeyQuestion,
1821
} from "../../../question";
1922
import { OpenAIEnvironmentVariables } from "../../constants";
@@ -206,6 +209,32 @@ export class CreateOrUpdateEnvironmentFileDriver implements StepDriver {
206209
}
207210
}
208211

212+
if (args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_MODEL_DEPLOYMENT_NAME]) {
213+
const matches = placeHolderReg.exec(
214+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_MODEL_DEPLOYMENT_NAME]
215+
);
216+
if (matches != null && matches.length > 1) {
217+
const result = await ctx.ui!.inputText({
218+
name: azureOpenAIDeploymentNameQuestion().name,
219+
title: azureOpenAIDeploymentNameQuestion().title as string,
220+
validation: (input: string): string | undefined => {
221+
if (input.length < 1) {
222+
return getLocalizedString(
223+
"driver.file.createOrUpdateEnvironmentFile.OpenAIDeploymentName.validation"
224+
);
225+
}
226+
},
227+
});
228+
if (result.isErr()) {
229+
return result;
230+
} else {
231+
envOutput.set(matches[1], result.value.result!);
232+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_MODEL_DEPLOYMENT_NAME] =
233+
result.value.result!;
234+
}
235+
}
236+
}
237+
209238
if (args.envs[OpenAIEnvironmentVariables.OPENAI_API_KEY]) {
210239
const matches = placeHolderReg.exec(args.envs[OpenAIEnvironmentVariables.OPENAI_API_KEY]);
211240
if (matches != null && matches.length > 1) {
@@ -229,6 +258,82 @@ export class CreateOrUpdateEnvironmentFileDriver implements StepDriver {
229258
}
230259
}
231260
}
261+
262+
if (args.envs[OpenAIEnvironmentVariables.OPENAI_ASSISTANT_ID]) {
263+
const matches = placeHolderReg.exec(
264+
args.envs[OpenAIEnvironmentVariables.OPENAI_ASSISTANT_ID]
265+
);
266+
if (matches != null && matches.length > 1) {
267+
const result = await ctx.ui!.inputText({
268+
name: openAIAssistantIdQuestion().name,
269+
title: openAIAssistantIdQuestion().title as string,
270+
validation: (input: string): string | undefined => {
271+
if (input.length < 1) {
272+
return getLocalizedString(
273+
"driver.file.createOrUpdateEnvironmentFile.OpenAIAssistantID.validation"
274+
);
275+
}
276+
},
277+
});
278+
if (result.isErr()) {
279+
return result;
280+
} else {
281+
envOutput.set(matches[1], result.value.result!);
282+
args.envs[OpenAIEnvironmentVariables.OPENAI_ASSISTANT_ID] = result.value.result!;
283+
}
284+
}
285+
}
286+
287+
if (args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_ASSISTANT_ID]) {
288+
const matches = placeHolderReg.exec(
289+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_ASSISTANT_ID]
290+
);
291+
if (matches != null && matches.length > 1) {
292+
const result = await ctx.ui!.inputText({
293+
name: azureOpenAIAssistantIdQuestion().name,
294+
title: azureOpenAIAssistantIdQuestion().title as string,
295+
validation: (input: string): string | undefined => {
296+
if (input.length < 1) {
297+
return getLocalizedString(
298+
"driver.file.createOrUpdateEnvironmentFile.OpenAIAssistantID.validation"
299+
);
300+
}
301+
},
302+
});
303+
if (result.isErr()) {
304+
return result;
305+
} else {
306+
envOutput.set(matches[1], result.value.result!);
307+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_ASSISTANT_ID] = result.value.result!;
308+
}
309+
}
310+
}
311+
312+
if (args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_EMBEDDING_DEPLOYMENT]) {
313+
const matches = placeHolderReg.exec(
314+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_EMBEDDING_DEPLOYMENT]
315+
);
316+
if (matches != null && matches.length > 1) {
317+
const result = await ctx.ui!.inputText({
318+
name: azureOpenAIEmbeddingDeploymentNameQuestion().name,
319+
title: azureOpenAIEmbeddingDeploymentNameQuestion().title as string,
320+
validation: (input: string): string | undefined => {
321+
if (input.length < 1) {
322+
return getLocalizedString(
323+
"driver.file.createOrUpdateEnvironmentFile.OpenAIEmbeddingDeploymentName.validation"
324+
);
325+
}
326+
},
327+
});
328+
if (result.isErr()) {
329+
return result;
330+
} else {
331+
envOutput.set(matches[1], result.value.result!);
332+
args.envs[OpenAIEnvironmentVariables.AZURE_OPENAI_EMBEDDING_DEPLOYMENT] =
333+
result.value.result!;
334+
}
335+
}
336+
}
232337
return ok(Void);
233338
}
234339

packages/fx-core/src/question/create.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,41 @@ export function azureOpenAIDeploymentNameQuestion(): TextInputQuestion {
10171017
};
10181018
}
10191019

1020+
export function openAIAssistantIdQuestion(): TextInputQuestion {
1021+
return {
1022+
type: "text",
1023+
name: QuestionNames.OpenAIAssistantID,
1024+
title: getLocalizedString("core.createProjectQuestion.llmService.openAIAssistantID.title"),
1025+
placeholder: getLocalizedString(
1026+
"core.createProjectQuestion.llmService.openAIAssistantID.placeholder"
1027+
),
1028+
};
1029+
}
1030+
1031+
export function azureOpenAIAssistantIdQuestion(): TextInputQuestion {
1032+
return {
1033+
type: "text",
1034+
name: QuestionNames.AzureOpenAIAssistantId,
1035+
title: getLocalizedString("core.createProjectQuestion.llmService.azureOpenAIAssistantID.title"),
1036+
placeholder: getLocalizedString(
1037+
"core.createProjectQuestion.llmService.azureOpenAIAssistantID.placeholder"
1038+
),
1039+
};
1040+
}
1041+
1042+
export function azureOpenAIEmbeddingDeploymentNameQuestion(): TextInputQuestion {
1043+
return {
1044+
type: "text",
1045+
name: QuestionNames.AzureOpenAIEmbeddingDeploymentName,
1046+
title: getLocalizedString(
1047+
"core.createProjectQuestion.llmService.azureOpenAIEmbeddingDeploymentName.title"
1048+
),
1049+
placeholder: getLocalizedString(
1050+
"core.createProjectQuestion.llmService.azureOpenAIEmbeddingDeploymentName.placeholder"
1051+
),
1052+
};
1053+
}
1054+
10201055
export function apiPluginStartQuestion(doesProjectExists?: boolean): SingleSelectQuestion {
10211056
return {
10221057
type: "singleSelect",

packages/fx-core/src/question/questionNames.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ export enum QuestionNames {
5252
LLMService = "llm-service",
5353
OpenAIKey = "openai-key",
5454
OpenAIEmbeddingModel = "openai-embedding-model",
55+
OpenAIAssistantID = "openai-assistant-id",
5556
AzureOpenAIKey = "azure-openai-key",
5657
AzureOpenAIEndpoint = "azure-openai-endpoint",
5758
AzureOpenAIDeploymentName = "azure-openai-deployment-name",
5859
AzureOpenAIEmbeddingDeploymentName = "azure-openai-embedding-deployment-name",
60+
AzureOpenAIAssistantId = "azure-openai-assistant-id",
5961
AzureAISearchApiKey = "azure-ai-search-api-key",
6062
AzureAISearchEndpoint = "azure-ai-search-endpoint",
6163

0 commit comments

Comments
 (0)