From c36386ac81681b84b5b50ecc7aabefed5b59ada2 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 12 May 2025 01:20:01 +0200 Subject: [PATCH] Scroll to bottom when chat is updating. --- profiler/src/profiler/TracyLlm.cpp | 8 ++++++++ profiler/src/profiler/TracyLlm.hpp | 1 + 2 files changed, 9 insertions(+) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index e9641733..1cbf7d25 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -189,6 +189,12 @@ void TracyLlm::Draw() ImGui::TextWrapped( "%s", line["content"].get().c_str() ); ImGui::PopStyleColor(); } + + if( m_wasUpdated ) + { + ImGui::SetScrollHereY( 1.f ); + m_wasUpdated = false; + } } ImGui::EndChild(); ImGui::Spacing(); @@ -225,6 +231,7 @@ void TracyLlm::Draw() m_chat->emplace_back( ollama::message( "user", m_input ) ); *m_input = 0; m_responding = true; + m_wasUpdated = true; m_jobs.emplace_back( WorkItem { .task = Task::SendMessage, @@ -341,6 +348,7 @@ bool TracyLlm::OnResponse( const ollama::response& response ) auto& back = m_chat->back()["content"]; const auto str = back.get(); back = str + response.as_simple_string(); + m_wasUpdated = true; auto& json = response.as_json(); if( json["done"] ) diff --git a/profiler/src/profiler/TracyLlm.hpp b/profiler/src/profiler/TracyLlm.hpp index 09662402..e73e69ca 100644 --- a/profiler/src/profiler/TracyLlm.hpp +++ b/profiler/src/profiler/TracyLlm.hpp @@ -87,6 +87,7 @@ private: bool m_busy = false; bool m_responding = false; bool m_stop = false; + bool m_wasUpdated = false; char* m_input; std::unique_ptr m_chat;