-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (23 loc) · 991 Bytes
/
test.py
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
import streamlit as st
from langchain_core.messages import HumanMessage
from main import graph
# Specify an ID for the thread
config = {"configurable": {"thread_id": "7"}}
st.title("MBCET Chatbot")
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Ask me anything about the college"):
st.chat_message("user").markdown(prompt)
st.session_state.messages.append({"role": "user", "content": f"{prompt}"})
with st.chat_message("assistant"):
messages = [HumanMessage(content=f"{prompt}")]
response = graph.invoke(
{"messages": messages},
stream_mode="values",
config=config
)
st.markdown(response['messages'][-1].content)
st.session_state.messages.append({"role": "assistant", "content": f"{response['messages'][-1].content}"})