nav13n commited on
Commit
9562f1b
·
1 Parent(s): 45fb393

first commit

Browse files
Files changed (2) hide show
  1. chain.py +0 -71
  2. chainlit.md +2 -2
chain.py DELETED
@@ -1,71 +0,0 @@
1
- # Langchain imports
2
- from langchain_community.document_loaders import PyMuPDFLoader
3
- from langchain.text_splitter import RecursiveCharacterTextSplitter
4
- from langchain_community.vectorstores import Qdrant
5
- from langchain.prompts import ChatPromptTemplate
6
- from langchain_openai import ChatOpenAI
7
- from langchain_openai import OpenAIEmbeddings
8
- from langchain_core.output_parsers import StrOutputParser
9
- from langchain.schema.runnable import RunnablePassthrough
10
- from dotenv import load_dotenv
11
-
12
-
13
- load_dotenv()
14
-
15
- ######################## Build RAG Chain #############################
16
- ######################################################################
17
-
18
- #### Load Documents
19
- loader = PyMuPDFLoader(
20
- "https://d18rn0p25nwr6d.cloudfront.net/CIK-0001326801/c7318154-f6ae-4866-89fa-f0c589f2ee3d.pdf"
21
- )
22
-
23
- documents = loader.load()
24
-
25
- #### Split Documents
26
- text_splitter = RecursiveCharacterTextSplitter(
27
- chunk_size = 800,
28
- chunk_overlap = 100
29
- )
30
-
31
- documents = text_splitter.split_documents(documents)
32
-
33
- embeddings = OpenAIEmbeddings(
34
- model="text-embedding-3-small"
35
- )
36
-
37
- ### Create Vector Store
38
- vector_store = Qdrant.from_documents(
39
- documents,
40
- embeddings,
41
- location=":memory:",
42
- collection_name="Meta 10k Filings",
43
- )
44
-
45
- ### Create Prmopt Template
46
- template = """Answer the question based only on the following context. If you cannot answer the question with the context, please respond with 'I don't know':
47
-
48
- Context:
49
- {context}
50
-
51
- Question:
52
- {question}
53
- """
54
- prompt = ChatPromptTemplate.from_template(template)
55
-
56
- def format_docs(docs):
57
- return "\n\n".join([d.page_content for d in docs])
58
-
59
- ### Setup RAG Chain
60
-
61
- retriever = vector_store.as_retriever(search_type="similarity_score_threshold",
62
- search_kwargs={"score_threshold": 0.6, "k":8})
63
- primary_qa_llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)
64
-
65
- rag_chain = (
66
- {"context": retriever | format_docs, "question": RunnablePassthrough()}
67
- | prompt
68
- | primary_qa_llm
69
- | StrOutputParser()
70
-
71
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
chainlit.md CHANGED
@@ -1,3 +1,3 @@
1
- # DocuSage
2
 
3
- DocuSage is a powerful document question-answering application that allows users to upload documents and ask natural language questions about their content. With cutting-edge AI technology, DocuSage provides accurate, concise answers in seconds, saving time and boosting productivity. Unlock valuable insights and let DocuSage be your sage guide through the world of document knowledge.
 
1
+ # Sage
2
 
3
+ SAGE is a digital assistant that helps employees quickly find answers to HR and policy questions.