From 4e8fb7870b72b2df8c79126877aadccd9d02c4bf Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 29 Jun 2025 14:08:40 +0200 Subject: [PATCH] Decrease context usage when removing chat content. --- profiler/src/profiler/TracyLlm.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index 9d08794c..a642d633 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -472,6 +472,15 @@ void TracyLlm::Draw() inputChanged = true; } + auto cit = it; + while( cit != m_chat.end() ) + { + const auto& content = (*cit)["content"].get_ref(); + const auto tokens = m_api->Tokenize( content, m_modelIdx ); + m_usedCtx -= tokens >= 0 ? tokens : content.size() / 4; + ++cit; + } + m_chat.erase( it, m_chat.end() ); if( m_responding ) m_stop = true; ImGui::PopID();