forked from neo4j-graphacademy/llm-chatbot-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
37 lines (27 loc) · 1.15 KB
/
bot.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
import streamlit as st
from utils import write_message
from agent import generate_response
# Cofigurando a página
st.set_page_config("Ebert, a movie expert to call your own!", page_icon=":movie_camera:")
# Configurando o estado da sessão.
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "assistant", "content": "Hi, I'm the GraphAcademy Chatbot! How can I help you?"},
]
# Submetendo a função manipulador (Handler Function).
def handle_submit(message):
# Manipulando a resposta.
with st.spinner('Thinking...'):
response = generate_response(message)
write_message('assistant', response)
# Criar a interface do Chat.
with st.container():
# Mostrar a mensagem mensagem armazenada no estado da sessão.
for message in st.session_state.messages:
write_message(message['role'], message['content'], save=False)
# Lidando com qualquer entrada do usuário.
if prompt := st.chat_input("What is up?"):
# Exibir mensagem do usuário no contêiner de mensagens de bate-papo.
write_message('user', prompt)
# Gerar uma resposta.
handle_submit(prompt)