-
Couldn't load subscription status.
- Fork 115
feat: Configurable chat icon #1853
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
Changes from 25 commits
76abfed
ebefd4f
da305e9
c2c0c27
11bc384
0b87414
33f94fb
d6b43a1
45e662e
2b2f105
fbce8d2
2f14281
048a36b
da8803c
277f681
4158e7a
12d6de3
b2d5d43
ced4c5c
68bac09
658a562
0eb0d36
0d64647
4907d7f
f252c2c
ee51869
a24fffc
23742f4
cebb4ef
c1445b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ type Message = { | |
| role: "user" | "assistant"; | ||
| chunk_type: "message_start" | "message_end" | null; | ||
| content_type: ContentType; | ||
| icon?: string; | ||
| operation: "append" | null; | ||
| }; | ||
| type ShinyChatMessage = { | ||
|
|
@@ -60,10 +61,12 @@ class ChatMessage extends LightElement { | |
| @property() content = "..."; | ||
| @property() content_type: ContentType = "markdown"; | ||
| @property({ type: Boolean, reflect: true }) streaming = false; | ||
| @property() icon = ""; | ||
|
|
||
| render() { | ||
| const noContent = this.content.trim().length === 0; | ||
| const icon = noContent ? ICONS.dots_fade : ICONS.robot; | ||
| // Show dots until we have content | ||
| const isEmpty = this.content.trim().length === 0; | ||
| const icon = isEmpty ? ICONS.dots_fade : this.icon || ICONS.robot; | ||
|
|
||
| return html` | ||
| <div class="message-icon">${unsafeHTML(icon)}</div> | ||
|
|
@@ -262,6 +265,7 @@ class ChatInput extends LightElement { | |
| } | ||
|
|
||
| class ChatContainer extends LightElement { | ||
| @property({ attribute: "icon-assistant" }) iconAssistant = ""; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel strongly, but have been using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was a little confused about this actually because it's I'd say my preference for kebab case attributes trends toward strong (I didn't care enough to figure out why it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand the question and the proposal here. Btw, since it's probably important context, shiny this behavior when writing tags: >>> from shiny import ui
>>> ui.div(foo_bar = "baz")
<div foo-bar="baz"></div>
>>> ui.div(fooBar = "baz")
<div fooBar="baz"></div>There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is why I was surprised you have underscores in the attributes. So I used But you're saying you used snake_case for attributes like As far as proposals, I'd prefer we pick one of these choices in order from first to last preference:
(I could be convinced into 2 or 3 if we have some guidelines for consistency, otherwise I'd much rather all attributes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still a bit confused, can we be a bit more specific? AFAIK, I'm using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the chat messages you pass JSON data (which has Anyway, I've always personally preferred:
But the event-data-direct-to-custom-element approach is easy and it would take a little more work to serialize those elements to JSON with kebab-case names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I overlooked the message handling aspect 🤦 . Would it make sense to you if Anyways, I don't think I have any strong opinions here and align with your preferences, so feel free to change as you see fit |
||
|
|
||
| private get input(): ChatInput { | ||
| return this.querySelector(CHAT_INPUT_TAG) as ChatInput; | ||
|
|
@@ -348,6 +352,11 @@ class ChatContainer extends LightElement { | |
|
|
||
| const TAG_NAME = | ||
| message.role === "user" ? CHAT_USER_MESSAGE_TAG : CHAT_MESSAGE_TAG; | ||
|
|
||
| if (this.iconAssistant) { | ||
| message.icon = message.icon || this.iconAssistant; | ||
| } | ||
|
|
||
| const msg = createElement(TAG_NAME, message); | ||
| this.messages.appendChild(msg); | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.