Skip to content

Commit 4a950ac

Browse files
committed
feature/claude haiku 3.5 model included
1 parent 2a1319e commit 4a950ac

File tree

7 files changed

+35
-99
lines changed

7 files changed

+35
-99
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ Each model has its own strengths and characteristics. You can switch between the
116116
1. Clone the repository:
117117

118118
```
119-
git clone https://github.com/aws-samples/live-chat-content-moderation-with-genai-on-aws.git
119+
git clone https://github.com/aws-solutions-library-samples/guidance-for-live-chat-content-moderation-with-generative-ai-on-aws.git
120120
```
121121

122122
2. Navigate to the project directory:
123123

124124
```
125-
cd live-chat-content-moderation-with-genai-on-aws/scripts
125+
cd guidance-for-live-chat-content-moderation-with-generative-ai-on-aws/scripts
126126
```
127127

128128
3. Run the installation script:
@@ -224,7 +224,7 @@ To switch between different AI models or prompts:
224224
./prompt-switch.bash <model-name>
225225
```
226226

227-
Replace `<model-name>` with one of the available options: `titan`, `haiku`, `llama` or `nova-micro`. The aforementioned `./install.bash` script configures Anthropic Claude Haiku to be used by default.
227+
Replace `<model-name>` with one of the available options: `titan`, `haiku`, `haiku-3.5`, `llama` or `nova-micro`. The aforementioned `./install.bash` script configures Anthropic Claude Haiku to be used by default.
228228

229229
### Updating the Front-End
230230

@@ -337,7 +337,7 @@ To delete all resources associated with the Live Chat Moderation system:
337337

338338
```
339339
cd backend/cdk
340-
cdk destroy
340+
cdk destroy --all
341341
```
342342

343343
## Next Steps
@@ -348,8 +348,6 @@ To further enhance your Live Chat Moderation system:
348348

349349
2. Implement User Authentication: Add user authentication to associate messages with verified user accounts.
350350

351-
3. You can improve DDoS attack protection of the solution by using AWS Shield Advanced to enable advanced protection up to the application layer (Layer 7 on OSI network model). Check reference blog https://aws.amazon.com/blogs/security/protect-apis-with-amazon-api-gateway-and-perimeter-protection-services/
352-
353351
## Notices
354352

355353
_Customers are responsible for making their own independent assessment of the information in this Guidance. This Guidance: (a) is for informational purposes only, (b) represents AWS current product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from AWS and its affiliates, suppliers or licensors. AWS products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. AWS responsibilities and liabilities to its customers are controlled by AWS agreements, and this Guidance is not part of, nor does it modify, any agreement between AWS and its customers._

backend/cdk/lib/api-stack.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,21 @@ export class Api extends cdk.NestedStack {
301301
statements: [
302302
new iam.PolicyStatement({
303303
effect: iam.Effect.ALLOW,
304-
actions: ["bedrock:ListFoundationModels", "bedrock:InvokeModel"],
304+
actions: [
305+
"bedrock:ListFoundationModels",
306+
"bedrock:InvokeModel",
307+
"bedrock:GetInferenceProfile",
308+
"bedrock:ListInferenceProfiles"
309+
],
305310
resources: [
306311
`arn:aws:bedrock:${this.region}:*:foundation-model/amazon.titan-text-premier-v1:0`,
307312
`arn:aws:bedrock:${this.region}:*:foundation-model/anthropic.claude-3-haiku-20240307-v1:0`,
308313
`arn:aws:bedrock:${this.region}:*:foundation-model/meta.llama3-8b-instruct-v1:0`,
309-
`arn:aws:bedrock:${this.region}:*:foundation-model/amazon.nova-micro-v1:0`
314+
`arn:aws:bedrock:${this.region}:*:foundation-model/amazon.nova-micro-v1:0`,
315+
// first '*' used instead of ${this.region} to allow internal cross-region inference
316+
// second '*' used before [model-id] to include both [model-id] and [region].[model-id]
317+
`arn:aws:bedrock:*:*:foundation-model/*anthropic.claude-3-5-haiku-20241022-v1:0`,
318+
`arn:aws:bedrock:*:*:inference-profile/*anthropic.claude-3-5-haiku-20241022-v1:0`,
310319
],
311320
}),
312321
],

backend/cdk/lib/database-stack.ts

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import * as cdk from "aws-cdk-lib";
22
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
3-
import * as cloudtrail from "aws-cdk-lib/aws-cloudtrail";
4-
import * as iam from "aws-cdk-lib/aws-iam";
5-
import * as s3 from "aws-cdk-lib/aws-s3";
63
import { Construct } from "constructs";
74

85
interface DatabaseProps extends cdk.NestedStackProps {
@@ -78,89 +75,6 @@ export class Database extends cdk.NestedStack {
7875
pointInTimeRecovery: true,
7976
});
8077

81-
/*
82-
// S3 Bucket for DynamoDB Data Events CloudTrail Logging
83-
const s3BucketDynamoDBCloudTrailLogging = new s3.Bucket(
84-
this,
85-
"s3BucketDynamoDBCloudTrailLogging",
86-
{
87-
encryption: s3.BucketEncryption.S3_MANAGED,
88-
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
89-
enforceSSL: true,
90-
autoDeleteObjects: true,
91-
removalPolicy: cdk.RemovalPolicy.DESTROY,
92-
}
93-
);
94-
95-
const trailName = "ChatModeration-DynamoDB-DataEvents-Trail";
96-
97-
const cloudTrailPrincipal = new iam.ServicePrincipal(
98-
"cloudtrail.amazonaws.com"
99-
);
100-
101-
s3BucketDynamoDBCloudTrailLogging.addToResourcePolicy(
102-
new iam.PolicyStatement({
103-
sid: "AllowGetBucketAcl",
104-
effect: iam.Effect.ALLOW,
105-
principals: [cloudTrailPrincipal],
106-
actions: ["s3:GetBucketAcl"],
107-
resources: [s3BucketDynamoDBCloudTrailLogging.bucketArn],
108-
conditions: {
109-
StringEquals: {
110-
"AWS:SourceArn": `arn:aws:cloudtrail:${this.region}:${this.account}:trail/${trailName}`,
111-
},
112-
},
113-
})
114-
);
115-
116-
s3BucketDynamoDBCloudTrailLogging.addToResourcePolicy(
117-
new iam.PolicyStatement({
118-
sid: "AllowPutObject",
119-
effect: iam.Effect.ALLOW,
120-
principals: [cloudTrailPrincipal],
121-
actions: ["s3:PutObject"],
122-
resources: [
123-
`arn:aws:s3:::${s3BucketDynamoDBCloudTrailLogging.bucketName}/AWSLogs/${this.account}/*`,
124-
],
125-
conditions: {
126-
StringEquals: {
127-
"s3:x-amz-acl": "bucket-owner-full-control",
128-
"AWS:SourceArn": `arn:aws:cloudtrail:${this.region}:${this.account}:trail/${trailName}`,
129-
},
130-
},
131-
})
132-
);
133-
134-
const cfnTrail = new cloudtrail.CfnTrail(this, "DynamoDBDataEventsTrail", {
135-
isLogging: true,
136-
s3BucketName: s3BucketDynamoDBCloudTrailLogging.bucketName,
137-
trailName: trailName,
138-
isMultiRegionTrail: false,
139-
includeGlobalServiceEvents: false,
140-
eventSelectors: [
141-
{
142-
dataResources: [
143-
{
144-
type: "AWS::DynamoDB::Table",
145-
values: [
146-
approvedMessagesTable.tableArn,
147-
unapprovedMessagesTable.tableArn,
148-
hallucinationsTable.tableArn,
149-
promptStoreTable.tableArn,
150-
],
151-
},
152-
],
153-
includeManagementEvents: false,
154-
readWriteType: "All",
155-
},
156-
],
157-
});
158-
159-
cfnTrail.addDependency(
160-
s3BucketDynamoDBCloudTrailLogging.node.defaultChild as cdk.CfnResource
161-
);
162-
*/
163-
16478
// Outputs
16579
this.approvedMessagesTableName = approvedMessagesTable.tableName;
16680
new cdk.CfnOutput(this, "ApprovedMessagesTableName", {

backend/cdk/lib/main-stack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class MainStack extends cdk.Stack {
6565
promptSwitchParameterName: promptSwitch.promptSwitchParameterName,
6666
});
6767

68-
// WAF Nested Stack in us-east-1
68+
// WAF Stack in us-east-1
6969
const wafStack = new Waf(this, 'Waf', {
7070
stackName: "Waf",
7171
crossRegionReferences: true,
@@ -85,6 +85,7 @@ export class MainStack extends cdk.Stack {
8585
const bedrockModels = [
8686
"amazon.titan-text-premier-v1:0",
8787
"anthropic.claude-3-haiku-20240307-v1:0",
88+
"anthropic.claude-3-5-haiku-20241022-v1:0",
8889
"meta.llama3-8b-instruct-v1:0",
8990
"amazon.nova-micro-v1:0"
9091
];

scripts/insert-prompt.bash

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Check if an argument is provided
44
if [ -z "$1" ]; then
5-
echo -e "\n${RED}[ERROR] Please provide a model name (titan, haiku, llama or nova-micro) as an argument."
5+
echo -e "\n${RED}[ERROR] Please provide a model name (titan, haiku, haiku-3.5, llama or nova-micro) as an argument."
66
exit 1
77
fi
88

@@ -37,12 +37,20 @@ case "$1" in
3737
;;
3838
haiku)
3939
MODEL_ID="anthropic.claude-3-haiku-20240307-v1:0"
40-
MODEL_NAME="Anthropic Claude Haiku"
40+
MODEL_NAME="Anthropic Claude Haiku 3"
4141
MODEL_OUTPUT_KEY="HaikuModelUUID"
4242
MAX_TOKENS=256
4343
TEMPERATURE=0
4444
TOP_P=0
4545
;;
46+
haiku-3.5)
47+
MODEL_ID="us.anthropic.claude-3-5-haiku-20241022-v1:0"
48+
MODEL_NAME="Anthropic Claude Haiku 3.5"
49+
MODEL_OUTPUT_KEY="Haiku35ModelUUID"
50+
MAX_TOKENS=256
51+
TEMPERATURE=0
52+
TOP_P=0
53+
;;
4654
llama)
4755
MODEL_ID="meta.llama3-8b-instruct-v1:0"
4856
MODEL_NAME="Meta Llama"
@@ -60,7 +68,7 @@ case "$1" in
6068
TOP_P=0
6169
;;
6270
*)
63-
echo -e "\n${RED}[ERROR] Invalid model name provided. Please use titan, haiku, llama or nova-micro."
71+
echo -e "\n${RED}[ERROR] Invalid model name provided. Please use titan, haiku, haiku-3.5, llama or nova-micro."
6472
exit 1
6573
;;
6674
esac

scripts/install.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ update_and_run_scripts() {
145145
run_script ./insert-prompt.bash titan
146146

147147
run_script ./insert-prompt.bash haiku
148+
149+
run_script ./insert-prompt.bash haiku-3.5
148150

149151
run_script ./insert-prompt.bash llama
150152

scripts/prompt-switch.bash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ STACK_NAME=$(jq -r 'keys[0]' "$CDK_OUTPUTS_FILE")
99
# Extract and export the necessary values
1010
TITAN_MODEL_UUID=$(jq -r '.'"$STACK_NAME"'.TitanModelUUID' "$CDK_OUTPUTS_FILE")
1111
HAIKU_MODEL_UUID=$(jq -r '.'"$STACK_NAME"'.HaikuModelUUID' "$CDK_OUTPUTS_FILE")
12+
HAIKU35_MODEL_UUID=$(jq -r '.'"$STACK_NAME"'.Haiku35ModelUUID' "$CDK_OUTPUTS_FILE")
1213
LLAMA_MODEL_UUID=$(jq -r '.'"$STACK_NAME"'.LlamaModelUUID' "$CDK_OUTPUTS_FILE")
1314
NOVA_MICRO_MODEL_UUID=$(jq -r '.'"$STACK_NAME"'.NovaMicroModelUUID' "$CDK_OUTPUTS_FILE")
1415
PROMPT_SWITCH_PARAMETER_NAME=$(jq -r '.'"$STACK_NAME"'.PromptSwitchParameterName' "$CDK_OUTPUTS_FILE")
@@ -22,7 +23,7 @@ NC='\033[0m' # No Color
2223

2324
# Check if an argument is provided
2425
if [ -z "$1" ]; then
25-
echo -e "\n${RED}[ERROR] Please provide a model name (titan, haiku, or llama) as an argument."
26+
echo -e "\n${RED}[ERROR] Please provide a model name (titan, haiku, haiku-3.5, llama or nova-micro) as an argument."
2627
exit 1
2728
fi
2829

@@ -34,6 +35,9 @@ case "$1" in
3435
haiku)
3536
NEW_ACTIVE_MODEL="$HAIKU_MODEL_UUID"
3637
;;
38+
haiku-3.5)
39+
NEW_ACTIVE_MODEL="$HAIKU35_MODEL_UUID"
40+
;;
3741
llama)
3842
NEW_ACTIVE_MODEL="$LLAMA_MODEL_UUID"
3943
;;

0 commit comments

Comments
 (0)