forked from neo4j-graphacademy/llm-chatbot-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
50 lines (42 loc) · 1.31 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
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
from utils import write_message
from solutions.agent import generate_response
# tag::setup[]
# Page Config
st.set_page_config("Ebert", page_icon=":movie_camera:")
# end::setup[]
# tag::session[]
# Set up Session State
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?"},
]
# end::session[]
# tag::submit[]
# Submit handler
def handle_submit(message):
"""
Submit handler:
You will modify this method to talk with an LLM and provide
context using data from Neo4j.
"""
# Handle the response
with st.spinner('Thinking...'):
# # TODO: Replace this with a call to your LLM
# from time import sleep
# sleep(1)
# write_message('assistant', message)
response = generate_response(message)
write_message('assistant', response)
# end::submit[]
# tag::chat[]
# Display messages in Session State
for message in st.session_state.messages:
write_message(message['role'], message['content'], save=False)
# Handle any user input
if prompt := st.chat_input("What is up?"):
# Display user message in chat message container
write_message('user', prompt)
# Generate a response
handle_submit(prompt)
# end::chat[]