Skip to content

Commit 65ea455

Browse files
author
Dinesh Sajwan
committed
feat(visualqa): fix defects
1 parent 64f9d2f commit 65ea455

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

lambda/aws-qa-appsync-opensearch/question_answering/src/lambda.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ def handler(event, context: LambdaContext) -> dict:
4141

4242
print(f"llm_response is {llm_response}")
4343
return llm_response
44+

lambda/aws-qa-appsync-opensearch/question_answering/src/qa_agent/chain.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_question_answering(arguments):
5454
# user didn't provide a image url as input, we use the RAG source against the entire knowledge base
5555
if response_generation_method == 'LONG_CONTEXT':
5656
if not filename:
57-
warning = 'Error: Image presigned url is required for LONG_CONTEXT approach, defaulting to RAG.'
57+
warning = 'Error: Filename url is required for LONG_CONTEXT approach, defaulting to RAG.'
5858
logger.warning(warning)
5959
llm_response = run_qa_agent_rag_on_image_no_memory(arguments)
6060
return llm_response

lambda/aws-qa-appsync-opensearch/question_answering/src/qa_agent/image_qa.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
bucket_name = os.environ['INPUT_BUCKET']
3939

40+
4041
def run_qa_agent_on_image_no_memory(input_params):
4142
logger.info("starting qa agent without memory on uploaded image")
4243

@@ -99,7 +100,7 @@ def run_qa_agent_rag_on_image_no_memory(input_params):
99100
qa_model=input_params['qa_model']
100101
embeddings_model = input_params['embeddings_model']
101102

102-
if 'modelId' in qa_model and 'embedding_model_id' in embeddings_model:
103+
if 'modelId' in qa_model and 'modelId' in embeddings_model:
103104
qa_model_id= qa_model['modelId']
104105
embedding_model_id = input_params['embeddings_model']['modelId']
105106
else:

lambda/aws-rag-appsync-stepfn-opensearch/s3_file_transformer/src/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
aws-lambda-powertools
2-
aws-xray-sdk==3.5.4
2+
aws-xray-sdk==2.12.1
33
fastjsonschema==2.19.1
4-
typing-extensions====4.7.0
4+
typing-extensions==4.7.0
55
boto3>=1.34.29
66
requests==2.31.0
77
langchain==0.1.4

src/patterns/gen-ai/aws-qa-appsync-opensearch/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* and limitations under the License.
1212
*/
1313
import * as path from 'path';
14-
import { Duration, Aws, Annotations } from 'aws-cdk-lib';
14+
import { Duration, Aws } from 'aws-cdk-lib';
1515
import * as appsync from 'aws-cdk-lib/aws-appsync';
1616
import * as cognito from 'aws-cdk-lib/aws-cognito';
1717
import * as ec2 from 'aws-cdk-lib/aws-ec2';
@@ -158,7 +158,7 @@ export interface QaAppsyncOpensearchProps {
158158
* Optional. Allows to provide custom lambda code
159159
* and settings instead of the existing
160160
*/
161-
readonly sagemakerEndpointName?: string
161+
readonly sagemakerEndpointName?: string;
162162
}
163163

164164
/**
@@ -465,13 +465,13 @@ export class QaAppsyncOpensearch extends BaseClass {
465465
resources: ['*'],
466466
}),
467467
);
468-
469-
if(props.sagemakerEndpointName){
468+
469+
if (props.sagemakerEndpointName) {
470470
question_answering_function_role.addToPolicy(
471471
new iam.PolicyStatement({
472472
effect: iam.Effect.ALLOW,
473473
actions: ['sagemaker:InvokeEndpoint'],
474-
resources: ['arn:'+ Aws.PARTITION +':sagemaker:' + Aws.ACCOUNT_ID + ':endpoint/*' ],
474+
resources: ['arn:'+ Aws.PARTITION +':sagemaker:' + Aws.ACCOUNT_ID + ':endpoint/*'],
475475
}),
476476
);
477477
}
@@ -554,7 +554,7 @@ export class QaAppsyncOpensearch extends BaseClass {
554554
true,
555555
);
556556

557-
const sagemakerEndpointNamestr = props.sagemakerEndpointName || ""
557+
const sagemakerEndpointNamestr = props.sagemakerEndpointName || '';
558558
const construct_docker_lambda_props = {
559559
code: lambda.DockerImageCode.fromImageAsset(
560560
path.join(
@@ -578,7 +578,7 @@ export class QaAppsyncOpensearch extends BaseClass {
578578
OPENSEARCH_DOMAIN_ENDPOINT: opensearch_helper.getOpenSearchEndpoint(props),
579579
OPENSEARCH_INDEX: props.openSearchIndexName,
580580
OPENSEARCH_SECRET_ID: SecretId,
581-
SAGEMAKER_ENDPOINT:sagemakerEndpointNamestr
581+
SAGEMAKER_ENDPOINT: sagemakerEndpointNamestr,
582582
},
583583
...(props.lambdaProvisionedConcurrency && {
584584
currentVersionOptions: {

src/patterns/gen-ai/aws-rag-appsync-stepfn-opensearch/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* and limitations under the License.
1212
*/
1313
import * as path from 'path';
14-
import { Duration, Aws, Stack, Annotations } from 'aws-cdk-lib';
14+
import { Duration, Aws, Stack } from 'aws-cdk-lib';
1515
import * as appsync from 'aws-cdk-lib/aws-appsync';
1616
import * as cognito from 'aws-cdk-lib/aws-cognito';
1717
import * as ec2 from 'aws-cdk-lib/aws-ec2';
@@ -536,7 +536,7 @@ export class RagAppsyncStepfnOpensearch extends BaseClass {
536536
actions: [
537537
'rekognition:DetectModerationLabels',
538538
],
539-
resources: ['arn:'+ Aws.PARTITION +':rekognition:' + Aws.ACCOUNT_ID + ':project/*' ],
539+
resources: ['arn:'+ Aws.PARTITION +':rekognition:' + Aws.REGION +':'+ Aws.ACCOUNT_ID + ':project/*'],
540540
}));
541541

542542
s3_transformer_job_function_role.addToPolicy(new iam.PolicyStatement({

test/patterns/gen-ai/aws-qa-appsync-opensearch/aws-qa-appsync-opensearch-serverless.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('QA Appsync Open search construct', () => {
5555
openSearchIndexName: 'demoindex',
5656
openSearchSecret: osSecret,
5757
cognitoUserPool: userPoolLoaded,
58+
sagemakerEndpointName: 'sageMakerEndpoint',
5859
};
5960

6061
qaTestConstruct = new QaAppsyncOpensearch(qaTestStack, 'test', qaTestProps);
@@ -89,6 +90,7 @@ describe('QA Appsync Open search construct', () => {
8990
},
9091
OPENSEARCH_INDEX: 'demoindex',
9192
OPENSEARCH_SECRET_ID: 'OSSecretId',
93+
SAGEMAKER_ENDPOINT: 'sageMakerEndpoint',
9294
},
9395
},
9496
});

test/patterns/gen-ai/aws-qa-appsync-opensearch/aws-qa-appsync-opensearch.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('QA Appsync Open search construct', () => {
5858
openSearchIndexName: 'demoindex',
5959
openSearchSecret: osSecret,
6060
cognitoUserPool: userPoolLoaded,
61+
sagemakerEndpointName: 'sageMakerEndpoint',
6162
};
6263

6364
qaTestConstruct = new QaAppsyncOpensearch(qaTestStack, 'test', qaTestProps);
@@ -87,6 +88,7 @@ describe('QA Appsync Open search construct', () => {
8788
OPENSEARCH_DOMAIN_ENDPOINT: 'osendppint.amazon.aws.com',
8889
OPENSEARCH_INDEX: 'demoindex',
8990
OPENSEARCH_SECRET_ID: 'OSSecretId',
91+
SAGEMAKER_ENDPOINT: 'sageMakerEndpoint',
9092
},
9193
},
9294
});
@@ -223,6 +225,7 @@ describe('QA Appsync Open search construct custom lambda', () => {
223225
openSearchSecret: osSecret,
224226
cognitoUserPool: userPoolLoaded,
225227
customDockerLambdaProps: customDockerLambdaProps,
228+
sagemakerEndpointName: 'sageMakerEndpoint',
226229
};
227230

228231
qaTestConstruct = new QaAppsyncOpensearch(qaTestStack, 'test', qaTestProps);
@@ -252,6 +255,7 @@ describe('QA Appsync Open search construct custom lambda', () => {
252255
OPENSEARCH_DOMAIN_ENDPOINT: 'osendppint.amazon.aws.com',
253256
OPENSEARCH_INDEX: 'demoindex',
254257
OPENSEARCH_SECRET_ID: 'OSSecretId',
258+
SAGEMAKER_ENDPOINT: 'sageMakerEndpoint',
255259
TEST_VAR: 'hello',
256260
},
257261
},

0 commit comments

Comments
 (0)