Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mynotes.md
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 5 additions & 4 deletions bedrock-chat-with-pdf/Admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
## s3_client
s3_client = boto3.client("s3")
BUCKET_NAME = os.getenv("BUCKET_NAME")
REGION = os.getenv("REGION")

## Bedrock
from langchain_community.embeddings import BedrockEmbeddings

#from langchain_community.embeddings import BedrockEmbeddings
from langchain_aws import BedrockEmbeddings
## Text Splitter
from langchain.text_splitter import RecursiveCharacterTextSplitter

Expand All @@ -19,8 +20,8 @@
## import FAISS
from langchain_community.vectorstores import FAISS

bedrock_client = boto3.client(service_name="bedrock-runtime")
bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v1", client=bedrock_client)
bedrock_client = boto3.client(service_name="bedrock-runtime", region_name=REGION)
bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v2:0", client=bedrock_client)

def get_unique_id():
return str(uuid.uuid4())
Expand Down
2 changes: 2 additions & 0 deletions bedrock-chat-with-pdf/Admin/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
streamlit
pypdf
langchain
langchain_community
langchain-aws
faiss-cpu
boto3
26 changes: 18 additions & 8 deletions bedrock-chat-with-pdf/User/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
## s3_client
s3_client = boto3.client("s3")
BUCKET_NAME = os.getenv("BUCKET_NAME")
REGION = os.getenv("REGION")

## Bedrock
from langchain_community.embeddings import BedrockEmbeddings
from langchain.llms.bedrock import Bedrock

#from langchain_community.embeddings import BedrockEmbeddings
from langchain_aws import BedrockEmbeddings
#from langchain.llms.bedrock import Bedrock
from langchain_aws import ChatBedrock
## prompt and chain
from langchain.prompts import PromptTemplate
from langchain.chains import RetrievalQA
Expand All @@ -24,8 +26,9 @@
## import FAISS
from langchain_community.vectorstores import FAISS

bedrock_client = boto3.client(service_name="bedrock-runtime")
bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v1", client=bedrock_client)

bedrock_client = boto3.client(service_name="bedrock-runtime", region_name=REGION)
bedrock_embeddings = BedrockEmbeddings(model_id="amazon.titan-embed-text-v2:0", client=bedrock_client)

folder_path="/tmp/"

Expand All @@ -38,8 +41,14 @@ def load_index():
s3_client.download_file(Bucket=BUCKET_NAME, Key="my_faiss.pkl", Filename=f"{folder_path}my_faiss.pkl")

def get_llm():
llm=Bedrock(model_id="anthropic.claude-v2:1", client=bedrock_client,
model_kwargs={'max_tokens_to_sample': 512})
llm = ChatBedrock(
client=bedrock_client,
model_id="anthropic.claude-3-haiku-20240307-v1:0",
)
# llm = BedrockChat(
# client=bedrock_client,
# model_id="anthropic.claude-3-haiku-20240307-v1:0",
# )
return llm

# get_response()
Expand Down Expand Up @@ -70,7 +79,8 @@ def get_response(llm,vectorstore, question ):
return_source_documents=True,
chain_type_kwargs={"prompt": PROMPT}
)
answer=qa({"query":question})
#answer=qa({"query":question})
answer = qa.invoke({"query": question})
return answer['result']


Expand Down
2 changes: 2 additions & 0 deletions bedrock-chat-with-pdf/User/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
streamlit
langchain
langchain_community
langchain-aws
faiss-cpu
boto3