-
Notifications
You must be signed in to change notification settings - Fork 1
/
webui.py
64 lines (47 loc) · 1.9 KB
/
webui.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
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
58
59
60
61
62
63
64
import streamlit as st
from llama_index.core.base.llms.types import ChatMessage
st.set_page_config(page_title="NoC RAGbot", page_icon=":robot_face:")
st.title("NoC RAGbot: Porozprávaj sa so svojimi dátami")
st.caption("Powered by LlamaIndex & Streamlit & OpenAI")
@st.cache_resource(show_spinner=False)
def init():
with st.spinner(text="Načítavam dokumenty, počkajte prosím."):
pass
# -------------------------
# Init RAGbot here
#
#
# -------------------------
bot = init()
def add_msg_to_ui_conversation(role: str, content: str) -> None:
st.session_state.messages.append(ChatMessage(role=role, content=str(content)))
# Initialize the chat message history
if "messages" not in st.session_state.keys():
initial_msg = ChatMessage(
role="assistant",
content="Ahoj, spýtaj sa niečo svojich dát!",
)
st.session_state.messages = [initial_msg]
# ---------------------------
# ---------------------------
if question := st.chat_input(
"Vaša otázka"
): # Prompt for user input and save to chat history
add_msg_to_ui_conversation(role="user", content=question)
# Display the prior chat messages
for message in st.session_state.messages:
with st.chat_message(message.role):
st.write(message.content)
# If last message is not from assistant, generate a new response
if st.session_state.messages[-1].role != "assistant":
with st.chat_message("assistant"):
with st.spinner("Pracujem na odpovedi..."):
placeholder = st.empty()
# -------------------------------------
# Ask question and retrieve asnwer here
#
#
# -------------------------------------
response = "Zatiaľ nič nie je implementované :/"
placeholder.markdown(response)
add_msg_to_ui_conversation(role="assistant", content=response)