Skip to content

Commit d8a501b

Browse files
author
Dinesh Sajwan
committed
feat(visualqa): updated model paramters and file name in igestion
1 parent 9ee580e commit d8a501b

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def run_qa_agent_rag_no_memory(input_params):
101101
logger.info("starting qa agent with rag approach without memory :: {input_params}")
102102

103103
base64_bytes = input_params['question'].encode("utf-8")
104-
model_id = input_params['embeddings_model']['modelId']
105-
print(f'model id :: {model_id}')
104+
embedding_model_id = input_params['embeddings_model']['modelId']
105+
qa_model_id = input_params['qa_model']['modelId']
106106
sample_string_bytes = base64.b64decode(base64_bytes)
107107
decoded_question = sample_string_bytes.decode("utf-8")
108108

@@ -129,7 +129,7 @@ def run_qa_agent_rag_no_memory(input_params):
129129
os.environ.get('OPENSEARCH_DOMAIN_ENDPOINT'),
130130
os.environ.get('OPENSEARCH_INDEX'),
131131
os.environ.get('OPENSEARCH_SECRET_ID'),
132-
model_id)
132+
embedding_model_id)
133133

134134
else:
135135
logger.info("_retriever already exists")

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

+2-16
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ def run_qa_agent_on_image_no_memory(input_params):
3333
}
3434
send_job_status(status_variables)
3535

36-
# 1 : load the document
37-
global _file_content
38-
global _current_file_name
39-
40-
bucket_name = os.environ['INPUT_BUCKET']
36+
4137
filename = input_params['filename']
4238
image_url = input_params['presignedurl']
4339
logger.info(f"Generating response to question for file {filename}")
@@ -52,15 +48,8 @@ def run_qa_agent_on_image_no_memory(input_params):
5248
send_job_status(status_variables)
5349
return
5450

55-
# 2 : run the question
5651
streaming = input_params.get("streaming", False)
57-
# TODO use streaming in response
58-
callback_manager = [StreamingCallbackHandler(status_variables)] if streaming else None
59-
60-
#_qa_llm = get_llm(callback_manager,"HuggingFaceM4/idefics-80b-instruct")
61-
#TODO : Update get_llm to support sagemaker as provider,
62-
# this needs to be updated with @alain changes
63-
print(f' get LLM Ideficsllm')
52+
callback_manager = [StreamingCallbackHandler(status_variables)] if streaming else None
6453
_qa_llm = Ideficsllm.sagemakerendpoint_llm("idefics")
6554

6655
if (_qa_llm is None):
@@ -71,8 +60,6 @@ def run_qa_agent_on_image_no_memory(input_params):
7160
send_job_status(status_variables)
7261
return status_variables
7362

74-
# 3: run LLM
75-
#template="User:{question}![]({image})<end_of_utterance>\nAssistant:"
7663
template = """\n\nUser: {question}![]({image})<end_of_utterance>
7764
\n\nAssistant:"""
7865
prompt = PromptTemplate(template=template, input_variables=["image", "question"])
@@ -82,7 +69,6 @@ def run_qa_agent_on_image_no_memory(input_params):
8269
logger.info(f'image is: {filename}')
8370
logger.info(f'decoded_question is: {decoded_question}')
8471
tmp = chain.predict(image=image_url, question=decoded_question)
85-
#answer = tmp.removeprefix(' ')
8672
answer=tmp.split("Assistant:",1)[1]
8773

8874
logger.info(f'tmp is: {tmp}')

lambda/aws-rag-appsync-stepfn-opensearch/embeddings_job/src/lambda.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def handler(event, context: LambdaContext) -> dict:
199199
if(extension == '.jpg' or extension == '.jpeg' or extension == '.png' or extension == '.svg'):
200200
# Try adding text to document
201201
#image_detal_file is created by aws rekognition
202-
img_load = image_loader(bucket_name, f"{name}-resized{extension}",f"{name}.txt")
202+
img_load = image_loader(bucket_name, filename,f"{name}.txt")
203203
sub_docs = img_load.load()
204204
for doc in sub_docs:
205205
doc.metadata['source'] = filename

lambda/aws-rag-appsync-stepfn-opensearch/input_validation/src/lambda.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def append_job_info(response, job_id, ignore_existing,modelid):
6262

6363
@tracer.capture_method
6464
def isvalid_file_format(file_name: str) -> bool:
65-
file_format = ['.pdf','.txt','.jpg','.jpeg','.png','.csv','.docx','.ppt','.html','.jpeg']
65+
file_format = ['.pdf','.txt','.jpg','.jpeg','.png','.svg']
6666
if file_name.endswith(tuple(file_format)):
6767
print(f'valid file format :: {file_format}')
6868
return True

0 commit comments

Comments
 (0)