Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,34 @@ from langchain.vectorstores import FAISS
|
|
| 9 |
from langchain.memory import ConversationBufferMemory
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
| 11 |
from langchain_groq import ChatGroq
|
|
|
|
|
|
|
|
|
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Load environment variables
|
| 14 |
load_dotenv()
|
| 15 |
|
|
|
|
| 9 |
from langchain.memory import ConversationBufferMemory
|
| 10 |
from langchain.chains import ConversationalRetrievalChain
|
| 11 |
from langchain_groq import ChatGroq
|
| 12 |
+
from langchain_groq import ChatGroq
|
| 13 |
+
from langchain.memory import ConversationBufferMemory
|
| 14 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 15 |
|
| 16 |
+
def get_conversation_chain(vectorstore):
|
| 17 |
+
try:
|
| 18 |
+
# Initialize Groq's Chat model
|
| 19 |
+
llm = ChatGroq(
|
| 20 |
+
model="llama2-70b-4096", # You can use other models like "mixtral-8x7b-32768"
|
| 21 |
+
temperature=0.5,
|
| 22 |
+
groq_api_key=groq_api_key
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Set up memory for the conversation
|
| 26 |
+
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 27 |
+
|
| 28 |
+
# Create the conversational retrieval chain
|
| 29 |
+
conversation_chain = ConversationalRetrievalChain.from_llm(
|
| 30 |
+
llm=llm,
|
| 31 |
+
retriever=vectorstore.as_retriever(),
|
| 32 |
+
memory=memory
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
logging.info("Conversation chain created successfully.")
|
| 36 |
+
return conversation_chain
|
| 37 |
+
except Exception as e:
|
| 38 |
+
logging.error(f"Error creating conversation chain: {e}")
|
| 39 |
+
st.error("An error occurred while setting up the conversation chain.")
|
| 40 |
# Load environment variables
|
| 41 |
load_dotenv()
|
| 42 |
|