Skip to content

Commit

Permalink
Chat append incremental (#1799)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Cheng <[email protected]>
  • Loading branch information
cpsievert and jcheng5 authored Dec 21, 2024
1 parent 1bc1cd2 commit ecc5c14
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion js/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Message = {
role: "user" | "assistant";
chunk_type: "message_start" | "message_end" | null;
content_type: ContentType;
operation: "append" | null;
};
type ShinyChatMessage = {
id: string;
Expand Down Expand Up @@ -423,7 +424,12 @@ class ChatContainer extends LightElement {
return;
}

lastMessage.setAttribute("content", message.content);
const content =
message.operation === "append"
? lastMessage.getAttribute("content") + message.content
: message.content;

lastMessage.setAttribute("content", content);

if (message.chunk_type === "message_end") {
this.lastMessage?.removeAttribute("streaming");
Expand Down
2 changes: 1 addition & 1 deletion shiny/www/py-shiny/chat/chat.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions shiny/www/py-shiny/chat/chat.js.map

Large diffs are not rendered by default.

0 comments on commit ecc5c14

Please sign in to comment.