pankajsingh3012 commited on
Commit
4274425
·
verified ·
1 Parent(s): a69ecdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -5,7 +5,7 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from langchain.chains import RetrievalQA
6
  from langchain_google_genai import GoogleGenerativeAI
7
  from langchain.prompts import PromptTemplate
8
- from langchain.chains import load_qa_chain, RetrievalQA
9
  import requests
10
  from bs4 import BeautifulSoup
11
  from urllib.parse import urljoin
@@ -110,12 +110,12 @@ if query and st.session_state.documents_loaded:
110
  # Create a PromptTemplate for the QA chain
111
  qa_prompt = PromptTemplate(template="Answer the following question based on the context provided:\n\n{context}\n\nQuestion: {question}\nAnswer:", input_variables=["context", "question"])
112
 
113
- # Load the QA chain
114
- qa_chain = load_qa_chain(
115
- prompt=qa_prompt,
116
  retriever=st.session_state.vector_store.as_retriever(),
 
117
  llm=llm,
118
- combine_documents_chain=True
119
  )
120
 
121
  response = qa_chain({"question": query})
@@ -125,4 +125,3 @@ if query and st.session_state.documents_loaded:
125
  st.write(response['source'])
126
  elif query:
127
  st.warning("Please crawl the CUDA documentation first.")
128
-
 
5
  from langchain.chains import RetrievalQA
6
  from langchain_google_genai import GoogleGenerativeAI
7
  from langchain.prompts import PromptTemplate
8
+ #from langchain.chains import load_qa_chain, RetrievalQA
9
  import requests
10
  from bs4 import BeautifulSoup
11
  from urllib.parse import urljoin
 
110
  # Create a PromptTemplate for the QA chain
111
  qa_prompt = PromptTemplate(template="Answer the following question based on the context provided:\n\n{context}\n\nQuestion: {question}\nAnswer:", input_variables=["context", "question"])
112
 
113
+ # Create the retrieval QA chain
114
+ qa_chain = RetrievalQA.from_chain_type(
 
115
  retriever=st.session_state.vector_store.as_retriever(),
116
+ chain_type="map_reduce",
117
  llm=llm,
118
+ prompt=qa_prompt
119
  )
120
 
121
  response = qa_chain({"question": query})
 
125
  st.write(response['source'])
126
  elif query:
127
  st.warning("Please crawl the CUDA documentation first.")