Skip to content

Commit 49998d3

Browse files
committed
chore: Use an alert class when response was cancelled
1 parent 5dc95a4 commit 49998d3

File tree

1 file changed

+13
-3
lines changed
  • shiny/templates/chat/llms/ollama-multi

1 file changed

+13
-3
lines changed

shiny/templates/chat/llms/ollama-multi/app.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ async def cancel_chat_stream(chat: ChatOllama, stream: ExtendedTask):
8383
chunk="end",
8484
stream_id=stream_id,
8585
)
86-
await chat.append_status_message("In-progress response was cancelled.", type="static")
86+
await chat.append_status_message(
87+
ui.div(
88+
"The previous response was cancelled.",
89+
class_="alert alert-warning",
90+
style="margin-inline: auto; width: max-content;"
91+
),
92+
type="static",
93+
)
8794

8895

8996
@reactive.effect
@@ -136,7 +143,9 @@ async def reset_chat():
136143
await chat.clear_messages()
137144
await chat.append_message("Hello! How can I help you today?")
138145
chat_client.set(ChatOllama(model=input.model()))
139-
await chat.append_status_message(ui.HTML(f"Using model <code>{input.model()}</code>"))
146+
await chat.append_status_message(
147+
ui.HTML(f"Using model <code>{input.model()}</code>")
148+
)
140149

141150

142151
@reactive.effect
@@ -162,7 +171,8 @@ async def edit_last_message():
162171

163172
# Find the index of the last user message
164173
last_user_index = next(
165-
(i for i, msg in enumerate(messages) if msg["role"] == "user"), None
174+
(i for i, msg in reversed(list(enumerate(messages))) if msg["role"] == "user"),
175+
None,
166176
)
167177
if last_user_index is None:
168178
raise ValueError("No user messages found")

0 commit comments

Comments
 (0)