Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -989,30 +989,32 @@ elif page == "Sessions":
|
|
| 989 |
memory = ConversationBufferWindowMemory(k=5, return_messages=True)
|
| 990 |
|
| 991 |
def get_chatmodel_response(question):
|
| 992 |
-
|
| 993 |
-
|
| 994 |
-
|
| 995 |
-
|
| 996 |
-
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
| 1015 |
-
|
|
|
|
|
|
|
| 1016 |
|
| 1017 |
# Session rename functionality
|
| 1018 |
new_title = st.text_input("Rename session:", value=session["title"])
|
|
@@ -1033,6 +1035,7 @@ elif page == "Sessions":
|
|
| 1033 |
mime='text/plain'
|
| 1034 |
)
|
| 1035 |
|
|
|
|
| 1036 |
# Define other tool functions here...
|
| 1037 |
def breathing_exercise():
|
| 1038 |
st.markdown("""
|
|
|
|
| 989 |
memory = ConversationBufferWindowMemory(k=5, return_messages=True)
|
| 990 |
|
| 991 |
def get_chatmodel_response(question):
|
| 992 |
+
session['flowmessages'].append(HumanMessage(content=question))
|
| 993 |
+
memory.save_context({"input": question}, {"output": ""}) # Save the input question to memory
|
| 994 |
+
chat_history = "\n".join([f"User: {msg.content}" if isinstance(msg, HumanMessage) else f"Bot: {msg.content}" for msg in session['flowmessages']])
|
| 995 |
+
prompt = CUSTOM_PROMPT.format(chat_history=chat_history, user_message=question, language=language)
|
| 996 |
+
messages = [SystemMessage(content=prompt)]
|
| 997 |
+
# Use st.session_state['chat'] here
|
| 998 |
+
answer = st.session_state['chat'](messages) # Pass list of messages to chat
|
| 999 |
+
session['flowmessages'].append(AIMessage(content=answer.content)) # Adjusted to handle response properly
|
| 1000 |
+
save_session(session) # Ensure session is saved after adding new messages
|
| 1001 |
+
return answer.content
|
| 1002 |
+
|
| 1003 |
+
|
| 1004 |
+
input = st.text_input("Input: ", key="input")
|
| 1005 |
+
submit = st.button("Ask the question")
|
| 1006 |
+
|
| 1007 |
+
if submit:
|
| 1008 |
+
response = get_chatmodel_response(input)
|
| 1009 |
+
save_session(session)
|
| 1010 |
+
st.experimental_rerun()
|
| 1011 |
+
if "flowmessages" in session:
|
| 1012 |
+
st.subheader("Chat")
|
| 1013 |
+
for message in session['flowmessages']:
|
| 1014 |
+
if isinstance(message, HumanMessage):
|
| 1015 |
+
st.write(user_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 1016 |
+
elif isinstance(message, AIMessage):
|
| 1017 |
+
st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 1018 |
|
| 1019 |
# Session rename functionality
|
| 1020 |
new_title = st.text_input("Rename session:", value=session["title"])
|
|
|
|
| 1035 |
mime='text/plain'
|
| 1036 |
)
|
| 1037 |
|
| 1038 |
+
|
| 1039 |
# Define other tool functions here...
|
| 1040 |
def breathing_exercise():
|
| 1041 |
st.markdown("""
|