Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +25 -8
src/streamlit_app.py
CHANGED
|
@@ -115,15 +115,32 @@ agent = create_deep_agent(
|
|
| 115 |
system_prompt=research_instructions,
|
| 116 |
)
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
st.
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if prompt := st.chat_input("Ask your research question..."):
|
|
|
|
|
|
|
| 123 |
st.chat_message("user").write(prompt)
|
|
|
|
|
|
|
| 124 |
with st.chat_message("assistant"):
|
| 125 |
st_callback = StreamlitCallbackHandler(st.container())
|
| 126 |
-
response = agent.invoke(
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
system_prompt=research_instructions,
|
| 116 |
)
|
| 117 |
|
| 118 |
+
# Initialize chat history
|
| 119 |
+
if "messages" not in st.session_state:
|
| 120 |
+
st.session_state["messages"] = [
|
| 121 |
+
{"role": "assistant", "content": "Hello! I’m your Deep Research Agent. What would you like to explore today?"}
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
# Display chat history
|
| 125 |
+
for msg in st.session_state.messages:
|
| 126 |
+
with st.chat_message(msg["role"]):
|
| 127 |
+
st.markdown(msg["content"])
|
| 128 |
+
|
| 129 |
+
# --- Chat Input ---
|
| 130 |
if prompt := st.chat_input("Ask your research question..."):
|
| 131 |
+
# Save user message
|
| 132 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 133 |
st.chat_message("user").write(prompt)
|
| 134 |
+
|
| 135 |
+
# Process assistant response
|
| 136 |
with st.chat_message("assistant"):
|
| 137 |
st_callback = StreamlitCallbackHandler(st.container())
|
| 138 |
+
response = agent.invoke(
|
| 139 |
+
{"messages": st.session_state.messages},
|
| 140 |
+
{"callbacks": [st_callback]},
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
# Extract and display assistant reply
|
| 144 |
+
reply = response["messages"][-1].content
|
| 145 |
+
st.markdown(reply)
|
| 146 |
+
st.session_state.messages.append({"role": "assistant", "content": reply})
|