From 356336e1853a43cb8e8d432346c61a288de86469 Mon Sep 17 00:00:00 2001 From: Xu Han Date: Thu, 27 Feb 2025 07:09:39 +0000 Subject: [PATCH 1/2] feat: optimize npm run config for china region --- source/infrastructure/cli/magic-config.ts | 37 ++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/source/infrastructure/cli/magic-config.ts b/source/infrastructure/cli/magic-config.ts index 3247a4bb..3b6de927 100644 --- a/source/infrastructure/cli/magic-config.ts +++ b/source/infrastructure/cli/magic-config.ts @@ -45,7 +45,7 @@ const embeddingModels = [ const supportedRegions = Object.values(SupportedRegion) as string[]; const supportedBedrockRegions = Object.values(SupportedBedrockRegion) as string[]; -const llms = [ +let llms = [ { provider: "bedrock", name: "anthropic.claude-3-sonnet-20240229-v1:0", @@ -195,6 +195,7 @@ async function processCreateOptions(options: any): Promise { ] const mandatoryQuestionAnswers: any = await prompt(mandatoryQuestions); + const deployInChina = mandatoryQuestionAnswers.intelliAgentDeployRegion.includes("cn"); let questions = [ { @@ -330,36 +331,38 @@ async function processCreateOptions(options: any): Promise { initial: options.enableChat ?? true, }, { - type: "input", + type: "select", name: "bedrockRegion", + hint: "ENTER to confirm selection", message: "Which region would you like to use Bedrock?", - initial: options.bedrockRegion ?? mandatoryQuestionAnswers.intelliAgentDeployRegion, - validate(bedrockRegion: string) { - if (Object.values(supportedBedrockRegions).includes(bedrockRegion)) { - return true; + choices: supportedBedrockRegions.map((region) => ({ name: region, value: region })), + initial: options.bedrockRegion, + validate(value: string) { + if ((this as any).state.answers.bedrockRegion) { + return value ? true : "Select a Bedrock Region"; } - return "Enter a valid region for Bedrock. Supported regions: " + supportedBedrockRegions.join(", "); + return true; }, skip(): boolean { - return (!(this as any).state.answers.enableChat); + return (deployInChina); }, }, { type: "confirm", name: "useOpenSourceLLM", message: "Do you want to use open source LLM(eg. Qwen, ChatGLM, IntermLM)?", - initial: options.useOpenSourceLLM ?? true, + initial: options.useOpenSourceLLM ?? false, skip(): boolean { - return (!(this as any).state.answers.enableChat); + return (!(this as any).state.answers.enableChat || deployInChina); }, }, { type: "confirm", name: "enableConnect", message: "Do you want to integrate it with Amazon Connect?", - initial: options.enableConnect ?? true, + initial: options.enableConnect ?? false, skip(): boolean { - return (!(this as any).state.answers.enableChat); + return (!(this as any).state.answers.enableChat || deployInChina); }, }, { @@ -376,8 +379,7 @@ async function processCreateOptions(options: any): Promise { return true; }, skip(): boolean { - return (!(this as any).state.answers.enableKnowledgeBase && - !(this as any).state.answers.enableChat); + return (!(this as any).state.answers.enableKnowledgeBase || deployInChina); }, }, { @@ -447,6 +449,13 @@ async function processCreateOptions(options: any): Promise { }; } + // Modify the config for China Region + if (deployInChina) { + answers.bedrockRegion = ""; + answers.defaultEmbedding = "bce-embedding-and-bge-reranker"; + llms = [] + } + // Create the config object const config = { prefix: mandatoryQuestionAnswers.prefix, From 822dabeed35bfd129623ba39fc7eb990c98d130c Mon Sep 17 00:00:00 2001 From: Xu Han Date: Thu, 27 Feb 2025 07:22:11 +0000 Subject: [PATCH 2/2] feat: update profile and online main lambda --- source/infrastructure/cli/magic-config.ts | 4 +++- source/infrastructure/lib/chat/chat-stack.ts | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/infrastructure/cli/magic-config.ts b/source/infrastructure/cli/magic-config.ts index 3b6de927..09cff402 100644 --- a/source/infrastructure/cli/magic-config.ts +++ b/source/infrastructure/cli/magic-config.ts @@ -57,9 +57,11 @@ async function getAwsAccountAndRegion() { let AWS_ACCOUNT; let AWS_REGION; + const aws_profile = process.env.AWS_PROFILE || "default"; + // Create STS client const stsClient = new STSClient({ - credentials: fromIni({ profile: "default" }) + credentials: fromIni({ profile: aws_profile }) }); try { diff --git a/source/infrastructure/lib/chat/chat-stack.ts b/source/infrastructure/lib/chat/chat-stack.ts index 3c3d2090..d6b88577 100644 --- a/source/infrastructure/lib/chat/chat-stack.ts +++ b/source/infrastructure/lib/chat/chat-stack.ts @@ -97,7 +97,7 @@ export class ChatStack extends NestedStack implements ChatStackOutputs { const lambdaLayers = new LambdaLayers(this); const apiLambdaOnlineSourceLayer = lambdaLayers.createOnlineMainLayer(); - const modelLayer = lambdaLayers.createModelDeploymentLayer(); + // const modelLayer = lambdaLayers.createModelDeploymentLayer(); const openAiKey = new secretsmanager.Secret(this, "OpenAiSecret", { @@ -143,7 +143,8 @@ export class ChatStack extends NestedStack implements ChatStackOutputs { BEDROCK_AWS_ACCESS_KEY_ID: props.config.chat.bedrockAk || "", BEDROCK_AWS_SECRET_ACCESS_KEY: props.config.chat.bedrockSk || "" }, - layers: [apiLambdaOnlineSourceLayer, modelLayer], + // layers: [apiLambdaOnlineSourceLayer, modelLayer], + layers: [apiLambdaOnlineSourceLayer], }); this.lambdaOnlineMain = lambdaOnlineMain.function;