Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate caching logic per page #232

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def get_parameter(name):

st.title("💬 Chat")

if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant", "content": "Ask me something about reinvent 2024?"}]
if "foundation_messages" not in st.session_state:
st.session_state["foundation_messages"] = [{"role": "assistant", "content": "Ask me something about reinvent 2024?"}]

for msg in st.session_state.messages:
for msg in st.session_state.foundation_messages:
st.chat_message(msg["role"]).write(msg["content"])

if prompt := st.chat_input():
st.chat_message("user").write(prompt)
st.session_state.messages.append(
st.session_state.foundation_messages.append(
{
"role": "user",
"content": prompt
Expand Down Expand Up @@ -62,7 +62,7 @@ def get_parameter(name):

except (ClientError, Exception) as e:
msg = f"ERROR: Can't invoke '{model_id}'. Reason: {e}"
st.session_state.messages.append(
st.session_state.foundation_messages.append(
{
"role": "assistant",
"content": msg
Expand All @@ -75,7 +75,7 @@ def get_parameter(name):

# Extract and print the response text.
msg = model_response["content"][0]["text"]
st.session_state.messages.append(
st.session_state.foundation_messages.append(
{
"role": "assistant",
"content": msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def get_parameter(name):

st.title("💬 Chat")

if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant", "content": "Ask me something about reinvent 2024?"}]
if "rag_messages" not in st.session_state:
st.session_state["rag_messages"] = [{"role": "assistant", "content": "Ask me something about reinvent 2024?"}]

for msg in st.session_state.messages:
for msg in st.session_state.rag_messages:
st.chat_message(msg["role"]).write(msg["content"])

if prompt := st.chat_input():
st.chat_message("user").write(prompt)
st.session_state.messages.append(
st.session_state.rag_messages.append(
{
"role": "user",
"content": prompt
Expand All @@ -49,7 +49,7 @@ def get_parameter(name):
chunks = event.get('chunk').get('attribution').get('citations')
for chunk in chunks:
msg = chunk['generatedResponsePart']['textResponsePart']['text']
st.session_state.messages.append(
st.session_state.rag_messages.append(
{
"role": "assistant",
"content": msg
Expand All @@ -58,7 +58,7 @@ def get_parameter(name):
st.chat_message("assistant").write(msg)
except:
msg = "Please give me a better prompt"
st.session_state.messages.append(
st.session_state.rag_messages.append(
{
"role": "assistant",
"content": msg
Expand Down
Loading