prasadnu commited on
Commit
a2ac876
·
1 Parent(s): 4a42b0c

model changed to Haiku 3.5 for query re=write

Browse files
RAG/rag_DocumentSearcher.py CHANGED
@@ -325,7 +325,7 @@ def query_(awsauth,inputs, session_id,search_types):
325
  if(hit["_source"]["image"]!="None"):
326
  with open(parent_dirname+'/figures/'+st.session_state.input_index+"/"+hit["_source"]["raw_element_type"].split("_")[1].replace(".jpg","")+"-resized.jpg", "rb") as read_img:
327
  input_encoded = base64.b64encode(read_img.read()).decode("utf8")
328
- context.append(str(id+1) + " : Reference from a image :" + invoke_models.generate_image_captions_llm(input_encoded,question))
329
  else:
330
  context.append(str(id+1) + " : Reference from a text chunk :" + hit["_source"]["processed_element"])
331
 
@@ -349,7 +349,7 @@ def query_(awsauth,inputs, session_id,search_types):
349
 
350
  llm_prompt = prompt_template.format(context="\n".join(total_context[0:3]),question=question)
351
  print("started LLM prompt: "+st.session_state.input_index)
352
- output = invoke_models.invoke_llm_model( "\n\nHuman: {input}\n\nAssistant:".format(input=llm_prompt) ,False)
353
  print("Finished LLM prompt: "+st.session_state.input_index)
354
  if(len(images_2)==0):
355
  images_2 = images
 
325
  if(hit["_source"]["image"]!="None"):
326
  with open(parent_dirname+'/figures/'+st.session_state.input_index+"/"+hit["_source"]["raw_element_type"].split("_")[1].replace(".jpg","")+"-resized.jpg", "rb") as read_img:
327
  input_encoded = base64.b64encode(read_img.read()).decode("utf8")
328
+ context.append(str(id+1) + " : Reference from a image :" + invoke_models.generate_image_captions_llm(input_encoded,question,"anthropic.claude-3-haiku-20240307-v1:0"))
329
  else:
330
  context.append(str(id+1) + " : Reference from a text chunk :" + hit["_source"]["processed_element"])
331
 
 
349
 
350
  llm_prompt = prompt_template.format(context="\n".join(total_context[0:3]),question=question)
351
  print("started LLM prompt: "+st.session_state.input_index)
352
+ output = invoke_models.invoke_llm_model( "\n\nHuman: {input}\n\nAssistant:".format(input=llm_prompt) ,False,"anthropic.claude-3-haiku-20240307-v1:0")
353
  print("Finished LLM prompt: "+st.session_state.input_index)
354
  if(len(images_2)==0):
355
  images_2 = images
utilities/invoke_models.py CHANGED
@@ -58,10 +58,12 @@ def invoke_model_mm(text,img):
58
  #print(response_body)
59
  return response_body.get("embedding")
60
 
61
- def invoke_llm_model(input,is_stream):
 
 
62
  if(is_stream == False):
63
  response = bedrock_runtime_client.invoke_model(
64
- modelId= "us.anthropic.claude-3-haiku-20240307-v1:0",#"us.anthropic.claude-3-5-haiku-20241022-v1:0",#"anthropic.claude-3-5-haiku-20241022-v1:0",#"anthropic.claude-3-5-sonnet-20240620-v1:0",,
65
  contentType = "application/json",
66
  accept = "application/json",
67
  performanceConfigLatency='optimized',
@@ -126,11 +128,12 @@ def read_from_table(file,question):
126
  agent_res = agent.invoke(question)['output']
127
  return agent_res
128
 
129
- def generate_image_captions_llm(base64_string,question):
130
-
 
131
 
132
  response = bedrock_runtime_client.invoke_model(
133
- modelId= "anthropic.claude-3-5-haiku-20241022-v1:0",
134
  contentType = "application/json",
135
  accept = "application/json",
136
 
 
58
  #print(response_body)
59
  return response_body.get("embedding")
60
 
61
+ def invoke_llm_model(input,is_stream,model_id):
62
+ if(model_id is None):
63
+ model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0"
64
  if(is_stream == False):
65
  response = bedrock_runtime_client.invoke_model(
66
+ modelId= model_id,#"us.anthropic.claude-3-5-haiku-20241022-v1:0",#"anthropic.claude-3-5-haiku-20241022-v1:0",#"anthropic.claude-3-5-sonnet-20240620-v1:0",,
67
  contentType = "application/json",
68
  accept = "application/json",
69
  performanceConfigLatency='optimized',
 
128
  agent_res = agent.invoke(question)['output']
129
  return agent_res
130
 
131
+ def generate_image_captions_llm(base64_string,question,model_id):
132
+ if(model_id is None):
133
+ model_id = "us.anthropic.claude-3-5-haiku-20241022-v1:0"
134
 
135
  response = bedrock_runtime_client.invoke_model(
136
+ modelId= model_id,
137
  contentType = "application/json",
138
  accept = "application/json",
139