Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -991,16 +991,35 @@ elif page == "Sessions":
|
|
| 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 |
-
|
| 997 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 998 |
answer = st.session_state['chat'](messages) # Pass list of messages to chat
|
| 999 |
-
|
| 1000 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1001 |
return answer.content
|
| 1002 |
|
| 1003 |
|
|
|
|
| 1004 |
input = st.text_input("Input: ", key="input")
|
| 1005 |
submit = st.button("Ask the question")
|
| 1006 |
|
|
|
|
| 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 |
+
|
| 995 |
+
# Prepare the chat history for the prompt
|
| 996 |
chat_history = "\n".join([f"User: {msg.content}" if isinstance(msg, HumanMessage) else f"Bot: {msg.content}" for msg in session['flowmessages']])
|
| 997 |
+
|
| 998 |
+
# Construct the prompt using the template
|
| 999 |
prompt = CUSTOM_PROMPT.format(chat_history=chat_history, user_message=question, language=language)
|
| 1000 |
+
|
| 1001 |
+
# Ensure the prompt is not empty
|
| 1002 |
+
if not prompt.strip():
|
| 1003 |
+
raise ValueError("The constructed prompt is empty. Check the message formatting.")
|
| 1004 |
+
|
| 1005 |
+
# Use HumanMessage instead of SystemMessage
|
| 1006 |
+
messages = [HumanMessage(content=prompt)]
|
| 1007 |
+
|
| 1008 |
+
# Get the response from the chat model
|
| 1009 |
answer = st.session_state['chat'](messages) # Pass list of messages to chat
|
| 1010 |
+
|
| 1011 |
+
# Ensure AI response is not empty
|
| 1012 |
+
if not answer or not answer.content.strip():
|
| 1013 |
+
raise ValueError("The AI response is empty. Check the prompt or input.")
|
| 1014 |
+
|
| 1015 |
+
# Append the AI response to the session
|
| 1016 |
+
session['flowmessages'].append(AIMessage(content=answer.content))
|
| 1017 |
+
save_session(session) # Save the session after appending new messages
|
| 1018 |
+
|
| 1019 |
return answer.content
|
| 1020 |
|
| 1021 |
|
| 1022 |
+
|
| 1023 |
input = st.text_input("Input: ", key="input")
|
| 1024 |
submit = st.button("Ask the question")
|
| 1025 |
|