-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_frontend.py
More file actions
34 lines (25 loc) · 1.15 KB
/
Copy pathstreamlit_frontend.py
File metadata and controls
34 lines (25 loc) · 1.15 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
import streamlit as st
from langgraph_backend import chatbot
from langchain_core.messages import HumanMessage
# st.session_state -> dict ->
CONFIG = {'configurable': {'thread_id': 'thread-1'}}
if 'message_history' not in st.session_state:
st.session_state['message_history'] = []
# loading the conversation history
for message in st.session_state['message_history']:
with st.chat_message(message['role']):
st.text(message['content'])
#{'role': 'user', 'content': 'Hi'}
#{'role': 'assistant', 'content': 'Hi=ello'}
user_input = st.chat_input('Type here')
if user_input:
# first add the message to message_history
st.session_state['message_history'].append({'role': 'user', 'content': user_input})
with st.chat_message('user'):
st.text(user_input)
response = chatbot.invoke({'messages': [HumanMessage(content=user_input)]}, config=CONFIG)
ai_message = response['messages'][-1].content
# first add the message to message_history
st.session_state['message_history'].append({'role': 'assistant', 'content': ai_message})
with st.chat_message('assistant'):
st.text(ai_message)