captain-awesome
commited on
Commit
•
b5fe45f
1
Parent(s):
c306f1c
Update app.py
Browse files
app.py
CHANGED
@@ -42,9 +42,9 @@ def get_context_retriever_chain(vector_store):
|
|
42 |
return retriever_chain
|
43 |
|
44 |
|
45 |
-
def get_conversational_rag_chain(retriever_chain):
|
46 |
|
47 |
-
llm = ChatOpenAI()
|
48 |
|
49 |
prompt = ChatPromptTemplate.from_messages([
|
50 |
("system", "Answer the user's questions based on the below context:\n\n{context}"),
|
@@ -56,9 +56,9 @@ def get_conversational_rag_chain(retriever_chain):
|
|
56 |
|
57 |
return create_retrieval_chain(retriever_chain, stuff_documents_chain)
|
58 |
|
59 |
-
def get_response(user_input):
|
60 |
retriever_chain = get_context_retriever_chain(st.session_state.vector_store)
|
61 |
-
conversation_rag_chain = get_conversational_rag_chain(retriever_chain)
|
62 |
|
63 |
response = conversation_rag_chain.invoke({
|
64 |
"chat_history": st.session_state.chat_history,
|
@@ -100,7 +100,7 @@ else:
|
|
100 |
#user_input
|
101 |
user_query = st.chat_input("Type your message here...")
|
102 |
if user_query is not None and user_query !="":
|
103 |
-
response = get_response(user_query)
|
104 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
105 |
st.session_state.chat_history.append(AIMessage(content=response))
|
106 |
|
|
|
42 |
return retriever_chain
|
43 |
|
44 |
|
45 |
+
def get_conversational_rag_chain(retriever_chain,openai_apikey):
|
46 |
|
47 |
+
llm = ChatOpenAI(openai_api_key=openai_apikey)
|
48 |
|
49 |
prompt = ChatPromptTemplate.from_messages([
|
50 |
("system", "Answer the user's questions based on the below context:\n\n{context}"),
|
|
|
56 |
|
57 |
return create_retrieval_chain(retriever_chain, stuff_documents_chain)
|
58 |
|
59 |
+
def get_response(user_input,openai_apikey):
|
60 |
retriever_chain = get_context_retriever_chain(st.session_state.vector_store)
|
61 |
+
conversation_rag_chain = get_conversational_rag_chain(retriever_chain,openai_apikey)
|
62 |
|
63 |
response = conversation_rag_chain.invoke({
|
64 |
"chat_history": st.session_state.chat_history,
|
|
|
100 |
#user_input
|
101 |
user_query = st.chat_input("Type your message here...")
|
102 |
if user_query is not None and user_query !="":
|
103 |
+
response = get_response(user_query,openai_apikey)
|
104 |
st.session_state.chat_history.append(HumanMessage(content=user_query))
|
105 |
st.session_state.chat_history.append(AIMessage(content=response))
|
106 |
|