Spaces:
Running
Running
Chandranshu Jain
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -69,7 +69,7 @@ def text_splitter(text):
|
|
69 |
#COHERE_API_KEY = os.getenv("COHERE_API_KEY")
|
70 |
#HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
|
71 |
|
72 |
-
def get_conversational_chain():
|
73 |
prompt_template = """
|
74 |
Given the following extracted parts of a long document and a question, create a final answer.
|
75 |
Answer the question as detailed as possible from the provided context, make sure to provide all the details, if the answer is not in
|
@@ -94,7 +94,7 @@ def get_conversational_chain():
|
|
94 |
|
95 |
pt = ChatPromptTemplate.from_template(prompt_template)
|
96 |
# Retrieve and generate using the relevant snippets of the blog.
|
97 |
-
retriever = db.as_retriever()
|
98 |
rag_chain = (
|
99 |
{"context": retriever, "question": RunnablePassthrough()}
|
100 |
| pt
|
@@ -110,7 +110,9 @@ def embedding(chunk,query):
|
|
110 |
db = Chroma.from_documents(chunk,embeddings)
|
111 |
doc = db.similarity_search(query)
|
112 |
print(doc)
|
113 |
-
|
|
|
|
|
114 |
response = chain.invoke(query)
|
115 |
print(response)
|
116 |
return response
|
|
|
69 |
#COHERE_API_KEY = os.getenv("COHERE_API_KEY")
|
70 |
#HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACE_API_KEY")
|
71 |
|
72 |
+
def get_conversational_chain(retriever):
|
73 |
prompt_template = """
|
74 |
Given the following extracted parts of a long document and a question, create a final answer.
|
75 |
Answer the question as detailed as possible from the provided context, make sure to provide all the details, if the answer is not in
|
|
|
94 |
|
95 |
pt = ChatPromptTemplate.from_template(prompt_template)
|
96 |
# Retrieve and generate using the relevant snippets of the blog.
|
97 |
+
#retriever = db.as_retriever()
|
98 |
rag_chain = (
|
99 |
{"context": retriever, "question": RunnablePassthrough()}
|
100 |
| pt
|
|
|
110 |
db = Chroma.from_documents(chunk,embeddings)
|
111 |
doc = db.similarity_search(query)
|
112 |
print(doc)
|
113 |
+
#Retrieve and generate using the relevant snippets of the blog.
|
114 |
+
retriever = doc.as_retriever()
|
115 |
+
chain = get_conversational_chain(retriever)
|
116 |
response = chain.invoke(query)
|
117 |
print(response)
|
118 |
return response
|