Skip to content

Scroll to the last message on mount

Denys Mishunov requested to merge 414883-open-chat-on-last-message into master

What does this MR do and why?

The MR makes sure the chat is scrolled to the latest message when mounted in case there are messages stored in cache.

Screenshots or screen recordings

Before After
Screen_Recording_2023-06-08_at_6.05.17_PM chat-scroll-to-last

How to set up and validate locally

  1. Follow the instructions to enable the AI features in your local GDK
  2. Follow the instructions on setting up the GitLab chat locally
  3. Enable the :super_sidebar_nav feature flag (Feature.enable(:anthropic_experimentation) in your rails console
  4. Enable the new super sidebar in your settings via the web interface: Screenshot_2023-05-26_at_11.20.04
  5. In Rails console (rails c), run the script to pre-populate the cache
Pre-populate chat cache
user = User.first
user_cache = Gitlab::Llm::Cache.new(user)
10.times do |i|
  # Add user message to cache with random Lorem Ipsum text
  user_payload = {
    request_id: "user#{i}",
    role: Gitlab::Llm::Cache::ROLE_USER,
    content: "User's Foo Bar #{i}"
  }
  user_cache.add(user_payload)

  # Add assistant message to user's cache with random Lorem Ipsum text
  assistant_payload = {
    request_id: "assistant#{i}",
    role: Gitlab::Llm::Cache::ROLE_ASSISTANT,
    content: "Assistant's response #{i}"
  }
  user_cache.add(assistant_payload)
end
last_user_payload = {
  request_id: "last-user",
  role: Gitlab::Llm::Cache::ROLE_USER,
  content: "Last user's Foo Bar"
}
user_cache.add(last_user_payload)

last_assistant_payload = {
  request_id: "assistant-last",
  role: Gitlab::Llm::Cache::ROLE_ASSISTANT,
  content: "This is the last assistant's response"
}
user_cache.add(last_assistant_payload)
  1. Open the GitLab chat in Help -> Ask GitLab Chat

The chat should be scrolled down to This is the last assistant's response as shown in the "After" video.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #414883

Edited by Denys Mishunov

Merge request reports