Skip to content

Commit ecc5c14

Browse files
cpsievertjcheng5
andauthored
Chat append incremental (#1799)
Co-authored-by: Joe Cheng <joe@posit.co>
1 parent 1bc1cd2 commit ecc5c14

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

js/chat/chat.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Message = {
1616
role: "user" | "assistant";
1717
chunk_type: "message_start" | "message_end" | null;
1818
content_type: ContentType;
19+
operation: "append" | null;
1920
};
2021
type ShinyChatMessage = {
2122
id: string;
@@ -423,7 +424,12 @@ class ChatContainer extends LightElement {
423424
return;
424425
}
425426

426-
lastMessage.setAttribute("content", message.content);
427+
const content =
428+
message.operation === "append"
429+
? lastMessage.getAttribute("content") + message.content
430+
: message.content;
431+
432+
lastMessage.setAttribute("content", content);
427433

428434
if (message.chunk_type === "message_end") {
429435
this.lastMessage?.removeAttribute("streaming");

shiny/www/py-shiny/chat/chat.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/chat/chat.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)