Skip to content

Commit

Permalink
chore(chatbot): 0.4.8 release update
Browse files Browse the repository at this point in the history
* Mistral support
* various bug fixes and enhancements
  • Loading branch information
skeppeler committed May 6, 2024
1 parent cce8cdb commit 0443cd0
Show file tree
Hide file tree
Showing 51 changed files with 2,332 additions and 235 deletions.
3 changes: 3 additions & 0 deletions packages/blueprints/gen-ai-chatbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ The following languages are supported for a custom chatbot:
* Japanese (日本語)
* Korean (한국어)
* Chinese (中文)
* Français
* Deutsch
* Español

## Deployment
After building your chatbot, you can also deploy it with this blueprint. Before a chatbot can be deployed with a CodeCatalyst workflow, you must enable model access.
Expand Down
8 changes: 8 additions & 0 deletions packages/blueprints/gen-ai-chatbot/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ export interface Options extends ParentOptions {
* @defaultEntropy 8
*/
stackDisambiguator?: string;

/**
* This project is focused on Antrophic Claude models; limit support is provided for Mistral models. Enabling this option
* means that only Mistral models will be used for *all* the chat features.
* @displayName Enable Mistral
*/
enableMistral?: boolean;
};
}

Expand Down Expand Up @@ -221,6 +228,7 @@ export class Blueprint extends ParentBlueprint {
bucketNamePrefix: options.code.bucketNamePrefix,
enableSelfRegistration: options.enableSelfRegistration === 'Enabled',
stackDisambiguator: options.code.stackDisambiguator,
enableMistral: options.code.enableMistral ?? false,
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
],
"exclude": [
"README.md",
"./backend/**/__pycache__",
"./backend/tests/**",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
Expand All @@ -29,6 +31,7 @@
"allowedIpV4AddressRanges": [{{#allowedIpV4AddressRanges}}"{{{value}}}"{{#comma}},{{/comma}}{{/allowedIpV4AddressRanges}}],
"allowedIpV6AddressRanges": [{{#allowedIpV6AddressRanges}}"{{{value}}}"{{#comma}},{{/comma}}{{/allowedIpV6AddressRanges}}],
"enableSelfRegistration": {{enableSelfRegistration}},
"enableMistral": {{enableMistral}},
"publishedApiAllowedIpV4AddressRanges": ["0.0.0.0/1", "128.0.0.0/1"],
"publishedApiAllowedIpV6AddressRanges": [
"0000:0000:0000:0000:0000:0000:0000:0000/1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ChatbotGenAiCdkStackProps extends StackProps {
readonly publishedApiAllowedIpV6AddressRanges: string[];
readonly allowedSignUpEmailDomains: string[];
readonly rdsSchedules: CronScheduleProps;
readonly enableMistral: boolean;
}

export class ChatbotGenAiCdkStack extends cdk.Stack {
Expand Down Expand Up @@ -93,6 +94,7 @@ export class ChatbotGenAiCdkStack extends cdk.Stack {
prefix: `${this.node.tryGetContext('bucketNamePrefix') ?? 'chatbot-frontend-assets'}-${this.account}-${this.region}`,
removalPolicy: this.node.tryGetContext('bucketRemovalPolicy') ?? 'DESTROY',
},
enableMistral: props.enableMistral,
});

const auth = new Auth(this, "Auth", {
Expand All @@ -118,21 +120,23 @@ export class ChatbotGenAiCdkStack extends cdk.Stack {
objectOwnership: ObjectOwnership.OBJECT_WRITER,
autoDeleteObjects: true,
versioned: true,
serverAccessLogsBucket: new Bucket(this, 'DdbBucketLogs', {
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
removalPolicy: RemovalPolicy.DESTROY,
lifecycleRules: [
{
enabled: true,
expiration: Duration.days(3653),
id: 'ExpireAfterTenYears',
},
],
versioned: true,
serverAccessLogsPrefix: 'self/',
}),
serverAccessLogsBucket: CF_SKIP_ACCESS_LOGGING_REGIONS.includes(this.region)
? undefined
: new Bucket(this, "DdbBucketLogs", {
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
removalPolicy: RemovalPolicy.DESTROY,
lifecycleRules: [
{
enabled: true,
expiration: Duration.days(3653),
id: "ExpireAfterTenYears",
},
],
versioned: true,
serverAccessLogsPrefix: "self/",
}),
});

const database = new Database(this, "Database", {
Expand Down Expand Up @@ -174,13 +178,14 @@ export class ChatbotGenAiCdkStack extends cdk.Stack {
backendApiEndpoint: backendApi.api.apiEndpoint,
webSocketApiEndpoint: websocket.apiEndpoint,
userPoolDomainPrefix: props.userPoolDomainPrefix,
enableMistral: props.enableMistral,
auth,
idp,
});

documentBucket.addCorsRule({
allowedMethods: [HttpMethods.PUT],
allowedOrigins: [frontend.getOrigin(), "http://localhost:5173"],
allowedOrigins: [frontend.getOrigin(), "http://localhost:5173", "*"],
allowedHeaders: ["*"],
maxAge: 3000,
});
Expand Down Expand Up @@ -228,60 +233,84 @@ export class ChatbotGenAiCdkStack extends cdk.Stack {
});
new CfnOutput(this, "AvailabilityZone0", {
value: vpc.availabilityZones[0],
exportName: this.disambiguateIdentifier("BedrockClaudeChatAvailabilityZone0"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatAvailabilityZone0"
),
});
new CfnOutput(this, "AvailabilityZone1", {
value: vpc.availabilityZones[1],
exportName: this.disambiguateIdentifier("BedrockClaudeChatAvailabilityZone1"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatAvailabilityZone1"
),
});
new CfnOutput(this, "PublicSubnetId0", {
value: vpc.publicSubnets[0].subnetId,
exportName: this.disambiguateIdentifier("BedrockClaudeChatPublicSubnetId0"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatPublicSubnetId0"
),
});
new CfnOutput(this, "PublicSubnetId1", {
value: vpc.publicSubnets[1].subnetId,
exportName: this.disambiguateIdentifier("BedrockClaudeChatPublicSubnetId1"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatPublicSubnetId1"
),
});
new CfnOutput(this, "PrivateSubnetId0", {
value: vpc.privateSubnets[0].subnetId,
exportName: this.disambiguateIdentifier("BedrockClaudeChatPrivateSubnetId0"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatPrivateSubnetId0"
),
});
new CfnOutput(this, "PrivateSubnetId1", {
value: vpc.privateSubnets[1].subnetId,
exportName: this.disambiguateIdentifier("BedrockClaudeChatPrivateSubnetId1"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatPrivateSubnetId1"
),
});
new CfnOutput(this, "DbConfigSecretArn", {
value: vectorStore.secret.secretArn,
exportName: this.disambiguateIdentifier("BedrockClaudeChatDbConfigSecretArn"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatDbConfigSecretArn"
),
});
new CfnOutput(this, "DbConfigHostname", {
value: vectorStore.cluster.clusterEndpoint.hostname,
exportName: this.disambiguateIdentifier("BedrockClaudeChatDbConfigHostname"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatDbConfigHostname"
),
});
new CfnOutput(this, "DbConfigPort", {
value: vectorStore.cluster.clusterEndpoint.port.toString(),
exportName: this.disambiguateIdentifier("BedrockClaudeChatDbConfigPort"),
});
new CfnOutput(this, "ConversationTableName", {
value: database.table.tableName,
exportName: this.disambiguateIdentifier("BedrockClaudeChatConversationTableName"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatConversationTableName"
),
});
new CfnOutput(this, "TableAccessRoleArn", {
value: database.tableAccessRole.roleArn,
exportName: this.disambiguateIdentifier("BedrockClaudeChatTableAccessRoleArn"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatTableAccessRoleArn"
),
});
new CfnOutput(this, "DbSecurityGroupId", {
value: vectorStore.securityGroup.securityGroupId,
exportName: this.disambiguateIdentifier("BedrockClaudeChatDbSecurityGroupId"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatDbSecurityGroupId"
),
});
new CfnOutput(this, "LargeMessageBucketName", {
value: largeMessageBucket.bucketName,
exportName: this.disambiguateIdentifier("BedrockClaudeChatLargeMessageBucketName"),
exportName: this.disambiguateIdentifier(
"BedrockClaudeChatLargeMessageBucketName"
),
});
}

private disambiguateIdentifier(identifier: string) {
const disambiguator = this.node.tryGetContext('stackDisambiguator');
const disambiguator = this.node.tryGetContext("stackDisambiguator");
return disambiguator ? `${identifier}-${disambiguator}` : identifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Auth extends Construct {
}
);
client.node.addDependency(googleProvider);
break;
}
case "oidc": {
const issuerUrl = secret
Expand All @@ -124,6 +125,7 @@ export class Auth extends Construct {
}
);
client.node.addDependency(oidcProvider);
break;
}
}
};
Expand All @@ -141,10 +143,16 @@ export class Auth extends Construct {
}

if (props.allowedSignUpEmailDomains.length >= 1) {
const checkEmailDomainFunction = new PythonFunction(this, 'CheckEmailDomain',{
const checkEmailDomainFunction = new PythonFunction(
this,
"CheckEmailDomain",
{
runtime: Runtime.PYTHON_3_12,
index: 'check_email_domain.py',
entry: path.join(__dirname, "../../backend/auth/check_email_domain"),
index: "check_email_domain.py",
entry: path.join(
__dirname,
"../../backend/auth/check_email_domain"
),
timeout: Duration.minutes(1),
environment: {
ALLOWED_SIGN_UP_EMAIL_DOMAINS_STR: JSON.stringify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface FrontendProps {
prefix: string;
removalPolicy: string;
};
enableMistral: boolean;
}

export class Frontend extends Construct {
Expand All @@ -34,7 +35,10 @@ export class Frontend extends Construct {
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
removalPolicy: props.assetBucket.removalPolicy === 'RETAIN' ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY,
removalPolicy:
props.assetBucket.removalPolicy === "RETAIN"
? RemovalPolicy.RETAIN
: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});

Expand Down Expand Up @@ -88,12 +92,14 @@ export class Frontend extends Construct {
backendApiEndpoint,
webSocketApiEndpoint,
userPoolDomainPrefix,
enableMistral,
auth,
idp,
}: {
backendApiEndpoint: string;
webSocketApiEndpoint: string;
userPoolDomainPrefix: string;
enableMistral: boolean;
auth: Auth;
idp: Idp;
}) {
Expand All @@ -106,6 +112,7 @@ export class Frontend extends Construct {
VITE_APP_WS_ENDPOINT: webSocketApiEndpoint,
VITE_APP_USER_POOL_ID: auth.userPool.userPoolId,
VITE_APP_USER_POOL_CLIENT_ID: auth.client.userPoolClientId,
VITE_APP_ENABLE_MISTRAL: enableMistral.toString(),
VITE_APP_REGION: region,
VITE_APP_USE_STREAMING: "true",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Runtime } from "aws-cdk-lib/aws-lambda";
import { aws_glue } from "aws-cdk-lib";
import { Database } from "./database";
import * as iam from "aws-cdk-lib/aws-iam";
import { CF_SKIP_ACCESS_LOGGING_REGIONS } from "../utils/constants";

export interface UsageAnalysisProps {
sourceDatabase: Database;
Expand All @@ -31,7 +32,7 @@ export class UsageAnalysis extends Construct {
).stackName.toLowerCase()}_usage_analysis`;
const DDB_EXPORT_TABLE_NAME = "ddb_export";

// Bucket to export DynamoDB data
// Bucket to export DynamoDB data
const ddbBucket = new s3.Bucket(this, "DdbBucket", {
encryption: s3.BucketEncryption.S3_MANAGED,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
Expand All @@ -40,21 +41,23 @@ export class UsageAnalysis extends Construct {
objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
autoDeleteObjects: true,
versioned: true,
serverAccessLogsBucket: new s3.Bucket(this, 'DdbBucketLogs', {
encryption: s3.BucketEncryption.S3_MANAGED,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
removalPolicy: RemovalPolicy.DESTROY,
lifecycleRules: [
{
enabled: true,
expiration: Duration.days(3653),
id: 'ExpireAfterTenYears',
},
],
versioned: true,
serverAccessLogsPrefix: 'self/',
}),
serverAccessLogsBucket: CF_SKIP_ACCESS_LOGGING_REGIONS.includes(this.region)
? undefined
: new s3.Bucket(this, "DdbBucketLogs", {
encryption: s3.BucketEncryption.S3_MANAGED,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
removalPolicy: RemovalPolicy.DESTROY,
lifecycleRules: [
{
enabled: true,
expiration: Duration.days(3653),
id: "ExpireAfterTenYears",
},
],
versioned: true,
serverAccessLogsPrefix: "self/",
}),
});

// Bucket for Athena query results
Expand Down Expand Up @@ -94,7 +97,11 @@ export class UsageAnalysis extends Construct {
},
{
name: "MessageMap",
type: glue.Schema.STRING,
type: glue.Schema.struct([{ name: "S", type: glue.Schema.STRING }]),
},
{
name: "IsLargeMessage",
type: glue.Schema.struct([{ name: "BOOL", type: glue.Schema.BOOLEAN }]),
},
{
name: "PK",
Expand Down
Loading

0 comments on commit 0443cd0

Please sign in to comment.