-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (45 loc) · 2.1 KB
/
app.py
File metadata and controls
57 lines (45 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
from core.langgraph_agent import WikipediaAgent
import uuid
import logging
from core.logging_config import setup_logging
# Configure logging
setup_logging()
logger = logging.getLogger(__name__)
st.set_page_config(page_title="Wikipedia Research Assistant", page_icon="📚")
# Initialize session state for chat history if it doesn't exist
if "messages" not in st.session_state:
logger.info("Initializing messages in session state")
st.session_state.messages = []
if "agent" not in st.session_state:
logger.info("Initializing WikipediaAgent")
st.session_state.agent = WikipediaAgent()
if "thread_id" not in st.session_state:
logger.info("Generating new thread ID")
st.session_state.thread_id = str(uuid.uuid4())
st.title("📚 Wikipedia Research Assistant")
st.write("Ask me anything and I'll search Wikipedia to find relevant information!")
# Display chat messages from history
logger.debug(f"Displaying {len(st.session_state.messages)} messages from history")
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Accept user input
if prompt := st.chat_input("What would you like to know?"):
logger.info(f"Received user input: {prompt}")
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
logger.debug("Added user message to chat history")
# Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
# Display assistant response in chat message container
with st.chat_message("assistant"):
with st.spinner("Searching Wikipedia..."):
logger.info("Querying WikipediaAgent")
response = st.session_state.agent.query(prompt, thread_id=st.session_state.thread_id)
logger.debug(f"Received response: {response}")
st.markdown(response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response})
logger.debug("Added assistant response to chat history")