-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
32 lines (24 loc) · 881 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from langchain.chains import RetrievalQA
from langchain_community.document_loaders import UnstructuredFileLoader
from langchain_community.llms import Ollama
from langchain_community.vectorstores import FAISS
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_text_splitters import CharacterTextSplitter
loader = UnstructuredFileLoader("ai_adoption_framework_whitepaper.pdf")
docs = loader.load()
text_splitter = CharacterTextSplitter(
separator="\n",
chunk_size=2000,
chunk_overlap=200
)
texts = text_splitter.split_documents(docs)
embeddings = HuggingFaceEmbeddings()
db = FAISS.from_documents(texts, embeddings)
llm = Ollama(model="llama3")
chain = RetrievalQA.from_chain_type(
llm,
retriever=db.as_retriever()
)
question = "Can you please summarize the document"
result = chain.invoke({"query": question})
print(result['result'])