Paul-Joshi commited on
Commit
080b037
·
verified ·
1 Parent(s): 0260572

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -43
app.py CHANGED
@@ -26,23 +26,11 @@ def method_get_text_chunks(text):
26
  #split the text into chunks
27
 
28
  #text_splitter = CharacterTextSplitter.from_tiktoken_encoder(chunk_size=7500, chunk_overlap=100)
29
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
30
  doc_splits = text_splitter.split_documents(text)
31
  return doc_splits
32
-
33
-
34
- def method_get_vectorstore(document_chunks):
35
- #convert text chunks into embeddings and store in vector database
36
-
37
- # create the open-source embedding function
38
- #embeddings = NomicEmbeddings(model="nomic-embed-text-v1.5")
39
- embeddings = HuggingFaceEmbeddings()
40
-
41
- # create a vectorstore from the chunks
42
- vector_store = Chroma.from_documents(document_chunks, embeddings)
43
- return vector_store
44
-
45
- def get_context_retriever_chain(vector_store, question):
46
  # Initialize the retriever
47
  retriever = vector_store.as_retriever()
48
 
@@ -60,40 +48,13 @@ def get_context_retriever_chain(vector_store, question):
60
 
61
  # Construct the RAG pipeline
62
  after_rag_chain = (
63
- {"context": retriever, "question": question}
64
  | after_rag_prompt
65
  | llm
66
  | StrOutputParser()
67
  )
68
 
69
- # Invoke the RAG pipeline and return the generated answer
70
  return after_rag_chain.invoke(question)
71
-
72
- # def get_context_retriever_chain(vector_store,question):
73
- # # Initialize the retriever
74
- # retriever = vector_store.as_retriever()
75
-
76
- # # Define the RAG template
77
- # after_rag_template = """Answer the question based only on the following context:
78
- # {context}
79
- # Question: {question}
80
- # """
81
-
82
- # # Create the RAG prompt template
83
- # after_rag_prompt = ChatPromptTemplate.from_template(after_rag_template)
84
-
85
- # # Initialize the Hugging Face language model (LLM)
86
- # llm = HuggingFaceHub(repo_id="mistralai/Mistral-7B-Instruct-v0.2")
87
-
88
- # # Construct the RAG pipeline
89
- # after_rag_chain = (
90
- # {"context": retriever, "question": RunnablePassthrough()}
91
- # | after_rag_prompt
92
- # | llm
93
- # | StrOutputParser()
94
- # )
95
-
96
- # return after_rag_chain.invoke(question)
97
 
98
  def main():
99
  st.set_page_config(page_title="Chat with websites", page_icon="🤖")
 
26
  #split the text into chunks
27
 
28
  #text_splitter = CharacterTextSplitter.from_tiktoken_encoder(chunk_size=7500, chunk_overlap=100)
29
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
30
  doc_splits = text_splitter.split_documents(text)
31
  return doc_splits
32
+
33
+ def get_context_retriever_chain(vector_store,question):
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Initialize the retriever
35
  retriever = vector_store.as_retriever()
36
 
 
48
 
49
  # Construct the RAG pipeline
50
  after_rag_chain = (
51
+ {"context": retriever, "question": RunnablePassthrough()}
52
  | after_rag_prompt
53
  | llm
54
  | StrOutputParser()
55
  )
56
 
 
57
  return after_rag_chain.invoke(question)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  def main():
60
  st.set_page_config(page_title="Chat with websites", page_icon="🤖")