Skip to content

Commit c7fdeaf

Browse files
committed
Merge branch 'sample/rfp-answers-with-genai' of https://github.com/lhgmnn/generative-ai-cdk-constructs-samples into sample/rfp-answers-with-genai
2 parents bd58022 + 2e84f6c commit c7fdeaf

File tree

13 files changed

+420
-232
lines changed

13 files changed

+420
-232
lines changed

samples/bedrock-agent/lib/bedrock-agent-stack.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ export class BedrockAgentStack extends cdk.Stack {
6565
});
6666

6767
const agent = new bedrock.Agent(this, 'Agent', {
68-
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_INSTANT_V1_2,
68+
foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
6969
instruction: 'You are a helpful and friendly agent that answers questions about literature.',
7070
knowledgeBases: [kb],
71-
enableUserInput: true,
71+
userInputEnabled: true,
7272
shouldPrepareAgent:true
7373
});
7474

@@ -79,23 +79,35 @@ export class BedrockAgentStack extends cdk.Stack {
7979
timeout:cdk.Duration.minutes(2)
8080
});
8181

82-
const actionGroup = new AgentActionGroup(this,'MyActionGroup',{
83-
actionGroupName: 'query-library',
82+
const actionGroup = new AgentActionGroup({
83+
name: 'query-library',
8484
description: 'Use these functions to get information about the books in the library.',
85-
actionGroupExecutor: {
86-
lambda: actionGroupFunction
87-
},
88-
actionGroupState: "ENABLED",
89-
apiSchema: bedrock.ApiSchema.fromAsset(path.join(__dirname, 'action-group.yaml')),
85+
executor: bedrock.ActionGroupExecutor.fromlambdaFunction(actionGroupFunction),
86+
enabled: true,
87+
apiSchema: bedrock.ApiSchema.fromLocalAsset(path.join(__dirname, 'action-group.yaml')),
9088
});
9189

92-
agent.addActionGroups([actionGroup])
90+
agent.addActionGroup(actionGroup);
9391

94-
agent.addAlias({
92+
const agentAlias2 = new bedrock.AgentAlias(this, 'myalias2', {
9593
aliasName: 'my-agent-alias',
96-
description:'alias for my agent'
97-
98-
})
94+
agent: agent,
95+
description: 'alias for my agent'
96+
});
97+
98+
// Add NAG suppression for the Agent's role policy
99+
NagSuppressions.addResourceSuppressionsByPath(
100+
this,
101+
`/${this.node.path}/Agent/Role/DefaultPolicy/Resource`,
102+
[
103+
{
104+
id: 'AwsSolutions-IAM5',
105+
reason: 'The Agent requires permissions to invoke the action group Lambda function',
106+
appliesTo: ['Resource::<ActionGroupFunctionFE14D1CB.Arn>:*'],
107+
},
108+
],
109+
true
110+
);
99111

100112
new cdk.CfnOutput(this, 'AgentId', {value: agent.agentId});
101113
new cdk.CfnOutput(this, 'KnowledgeBaseId', {value: kb.knowledgeBaseId});
@@ -108,10 +120,29 @@ export class BedrockAgentStack extends cdk.Stack {
108120
{
109121
id: 'AwsSolutions-IAM4',
110122
reason: 'ActionGroup Lambda uses the AWSLambdaBasicExecutionRole AWS Managed Policy.',
123+
},
124+
{
125+
id: 'AwsSolutions-L1',
126+
reason: 'Using Python 3.12 as the latest runtime version for Lambda.',
111127
}
112128
],
113129
true,
114130
);
131+
NagSuppressions.addResourceSuppressionsByPath(
132+
this,
133+
`/${this.node.path}/Agent/Role/DefaultPolicy`,
134+
[
135+
{
136+
id: 'AwsSolutions-IAM5',
137+
reason: 'The Lambda function requires broad permissions for logging and invocation.',
138+
appliesTo: [
139+
'Action::lambda:InvokeFunction',
140+
'Action::logs:*'
141+
],
142+
},
143+
],
144+
true,
145+
);
115146
NagSuppressions.addResourceSuppressionsByPath(
116147
this,
117148
`/${this.node.path}/LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a/ServiceRole`,

samples/bedrock-agent/package-lock.json

Lines changed: 40 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/bedrock-agent/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"@types/jest": "^27.5.2",
1515
"@types/node": "10.17.27",
1616
"@types/prettier": "2.6.0",
17-
"aws-cdk": "2.162.1",
17+
"aws-cdk": "2.176.0",
1818
"jest": "^27.5.1",
1919
"ts-jest": "^27.1.4",
2020
"ts-node": "^10.9.1",
2121
"typescript": "~3.9.7"
2222
},
2323
"dependencies": {
24-
"@aws-cdk/aws-lambda-python-alpha": "^2.162.1-alpha.0",
25-
"@cdklabs/generative-ai-cdk-constructs": "^0.1.275",
26-
"aws-cdk-lib": "^2.162.1",
24+
"@aws-cdk/aws-lambda-python-alpha": "^2.176.0-alpha.0",
25+
"@cdklabs/generative-ai-cdk-constructs": "^0.1.290",
26+
"aws-cdk-lib": "^2.176.0",
2727
"cdk-nag": "^2.28.13",
2828
"constructs": "^10.0.0",
2929
"source-map-support": "^0.5.21"

samples/contract-compliance-analysis/front-end/package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/contract-compliance-analysis/front-end/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
"prettier-plugin-tailwindcss": "^0.5.5",
4747
"tailwindcss": "^3.3.3",
4848
"typescript": "^5.0.2",
49-
"vite": "^4.5.5"
49+
"vite": "^4.5.9"
5050
}
5151
}

samples/python-samples/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
env = cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'),
1414
region=os.getenv('CDK_DEFAULT_REGION'))
1515

16+
1617
#---------------------------------------------------------------------------
1718
# Bedrock knowledge base with OpenSearch
1819
#---------------------------------------------------------------------------
@@ -23,6 +24,7 @@
2324

2425
#---------------------------------------------------------------------------
2526
# Bedrock knowledge base with Amazon RDS Aurora PostgreSQL
27+
# uncomment this if you want to deploy Amazon RDS Aurora PostgreSQL
2628
#---------------------------------------------------------------------------
2729

2830

@@ -31,6 +33,16 @@
3133
# )
3234

3335

36+
#---------------------------------------------------------------------------
37+
# Bedrock knowledge base with Pinecone
38+
# uncomment this if you want to deploy Pinecone
39+
#---------------------------------------------------------------------------
40+
41+
42+
# BedrockPineconeStack(app, "BedrockPineconeStack",
43+
# env=env
44+
# )
45+
3446

3547
app.synth()
3648

0 commit comments

Comments
 (0)