Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from dotenv import load_dotenv
|
|
6 |
import time
|
7 |
from langchain.vectorstores import Chroma
|
8 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
|
9 |
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
|
10 |
from langchain_groq import ChatGroq
|
11 |
from langchain.chains import RetrievalQA, LLMChain
|
@@ -248,19 +249,22 @@ Remember to maintain a professional, clear tone and ensure all medicine recommen
|
|
248 |
Answer:"""
|
249 |
|
250 |
# Create the QA chain with correct variables
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
qa = RetrievalQA.from_chain_type(
|
252 |
llm=llm,
|
253 |
chain_type="stuff",
|
254 |
retriever=retriever,
|
255 |
-
|
256 |
chain_type_kwargs={
|
257 |
"prompt": PromptTemplate(
|
258 |
template=prompt_template,
|
259 |
input_variables=["context", "question"]
|
260 |
-
)
|
261 |
-
"memory_key": "chat_history", # Specify the memory key
|
262 |
-
"input_key": "question", # Specify which key to use for memory
|
263 |
-
"output_key": "answer" # Specify the output key
|
264 |
}
|
265 |
)
|
266 |
|
|
|
6 |
import time
|
7 |
from langchain.vectorstores import Chroma
|
8 |
from langchain.embeddings import HuggingFaceEmbeddings
|
9 |
+
from langchain.memory import ConversationBufferMemory
|
10 |
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
|
11 |
from langchain_groq import ChatGroq
|
12 |
from langchain.chains import RetrievalQA, LLMChain
|
|
|
249 |
Answer:"""
|
250 |
|
251 |
# Create the QA chain with correct variables
|
252 |
+
memory = ConversationBufferMemory(
|
253 |
+
memory_key="chat_history",
|
254 |
+
input_key="question",
|
255 |
+
output_key="answer"
|
256 |
+
)
|
257 |
+
|
258 |
qa = RetrievalQA.from_chain_type(
|
259 |
llm=llm,
|
260 |
chain_type="stuff",
|
261 |
retriever=retriever,
|
262 |
+
memory=memory,
|
263 |
chain_type_kwargs={
|
264 |
"prompt": PromptTemplate(
|
265 |
template=prompt_template,
|
266 |
input_variables=["context", "question"]
|
267 |
+
)
|
|
|
|
|
|
|
268 |
}
|
269 |
)
|
270 |
|