Skip to content

Commit

Permalink
Add a dot at the end of chat lines during model replies to make the r…
Browse files Browse the repository at this point in the history
…esponses look smoother. (#262)

* add dot at the end of chatline

* delete pub of  the State

* move the arm back
  • Loading branch information
Guocork authored Nov 18, 2024
1 parent 3deaa69 commit b01857b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/chat/chat_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,24 @@ impl ChatLineRef {
inner.label(id!(avatar_label)).set_text(text);
}

pub fn set_message_text(&mut self, cx: &mut Cx, text: &str) {
pub fn set_message_text(&mut self, cx: &mut Cx, text: &str, is_streaming: bool) {
let Some(mut inner) = self.borrow_mut() else {
return;
};

match inner.edition_state {

ChatLineState::Editable | ChatLineState::NotEditable => {
inner.text_input(id!(input)).set_text(text.trim());
inner.label(id!(plain_text_message)).set_text(text.trim());
inner.markdown(id!(markdown_message)).set_text(text.trim());
if is_streaming && !text.is_empty() {
let output = format!("{}{}", text, "●");
inner.text_input(id!(input)).set_text(&output.trim());
inner.label(id!(plain_text_message)).set_text(&output.trim());
inner.markdown(id!(markdown_message)).set_text(&output.trim());
} else {
inner.text_input(id!(input)).set_text(text.trim());
inner.label(id!(plain_text_message)).set_text(text.trim());
inner.markdown(id!(markdown_message)).set_text(text.trim());
}

// We know only AI assistant messages could be empty, so it is never
// displayed in user's chat lines.
Expand Down
3 changes: 2 additions & 1 deletion src/chat/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ impl ChatPanel {
chat_line_item.set_regenerate_button_visible(true);
};

chat_line_item.set_message_text(cx, &chat_line_data.content);
chat_line_item.set_message_id(chat_line_data.id);

// Disable actions for the last chat line when model is streaming
Expand All @@ -897,8 +896,10 @@ impl ChatPanel {
}
) && item_id == messages_count - 1
{
chat_line_item.set_message_text(cx, &chat_line_data.content, true);
chat_line_item.set_actions_enabled(cx, false);
} else {
chat_line_item.set_message_text(cx, &chat_line_data.content, false);
chat_line_item.set_actions_enabled(cx, true);
}

Expand Down

0 comments on commit b01857b

Please sign in to comment.