Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,13 +33,22 @@ def chat_with_ai(user, message):
|
|
| 33 |
memory.chat_memory.add_message(msg)
|
| 34 |
memory.chat_memory.add_message(HumanMessage(content=message))
|
| 35 |
|
| 36 |
-
response = model.invoke([SystemMessage(content="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
parsed_response = output_parser.parse(response.content.strip())
|
| 38 |
save_chat(history_store, message, parsed_response)
|
| 39 |
return parsed_response
|
| 40 |
|
| 41 |
# Streamlit UI
|
| 42 |
-
st.title("
|
| 43 |
|
| 44 |
# User session management
|
| 45 |
if "user" not in st.session_state:
|
|
|
|
| 33 |
memory.chat_memory.add_message(msg)
|
| 34 |
memory.chat_memory.add_message(HumanMessage(content=message))
|
| 35 |
|
| 36 |
+
response = model.invoke([SystemMessage(content=f"""
|
| 37 |
+
You are a data science tutor. Answer ONLY data science-related questions.
|
| 38 |
+
If the user asks something unrelated, politely decline.
|
| 39 |
+
Keep the conversation aware using memory.
|
| 40 |
+
|
| 41 |
+
Conversation history: {conversation_history}
|
| 42 |
+
|
| 43 |
+
User: {user_input}
|
| 44 |
+
""")] + memory.chat_memory.messages)
|
| 45 |
+
|
| 46 |
parsed_response = output_parser.parse(response.content.strip())
|
| 47 |
save_chat(history_store, message, parsed_response)
|
| 48 |
return parsed_response
|
| 49 |
|
| 50 |
# Streamlit UI
|
| 51 |
+
st.title("Data Science Tutor")
|
| 52 |
|
| 53 |
# User session management
|
| 54 |
if "user" not in st.session_state:
|