From 3d9b228177cc9ef12f1701b65d8ffb693c228be6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 31 Dec 2025 17:08:35 +0100 Subject: [PATCH] Allow disabling rendering of thinking regions. --- profiler/src/profiler/TracyLlm.cpp | 2 +- profiler/src/profiler/TracyLlmChat.cpp | 98 ++++++++++++++------------ profiler/src/profiler/TracyLlmChat.hpp | 2 +- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index e5fed522..c66624cf 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -451,7 +451,7 @@ void TracyLlm::Draw() } ImGui::PushID( turnIdx++ ); - if( !m_chatUi->Turn( role, line ) ) + if( !m_chatUi->Turn( role, line, true ) ) { if( role == TracyLlmChat::TurnRole::Assistant ) { diff --git a/profiler/src/profiler/TracyLlmChat.cpp b/profiler/src/profiler/TracyLlmChat.cpp index ce790355..089d6c32 100644 --- a/profiler/src/profiler/TracyLlmChat.cpp +++ b/profiler/src/profiler/TracyLlmChat.cpp @@ -72,7 +72,7 @@ void TracyLlmChat::End() } } -bool TracyLlmChat::Turn( TurnRole role, const nlohmann::json& json ) +bool TracyLlmChat::Turn( TurnRole role, const nlohmann::json& json, bool think ) { bool keep = true; const auto& roleData = roles[(int)role]; @@ -175,22 +175,25 @@ bool TracyLlmChat::Turn( TurnRole role, const nlohmann::json& json ) } else { - if( json.contains( "reasoning_content" ) ) + if( think ) { - ThinkScope( !roleChange ); - if( m_thinkOpen ) + if( json.contains( "reasoning_content" ) ) { - auto& reasoning = json["reasoning_content"].get_ref(); - PrintThink( reasoning.c_str(), reasoning.size() ); + ThinkScope( !roleChange ); + if( m_thinkOpen ) + { + auto& reasoning = json["reasoning_content"].get_ref(); + PrintThink( reasoning.c_str(), reasoning.size() ); + } } - } - if( json.contains( "tool_calls" ) ) - { - ThinkScope( !roleChange ); - if( m_thinkOpen ) + if( json.contains( "tool_calls" ) ) { - auto calls = json["tool_calls"].dump( 2 ); - PrintToolCall( calls.c_str(), calls.size() ); + ThinkScope( !roleChange ); + if( m_thinkOpen ) + { + auto calls = json["tool_calls"].dump( 2 ); + PrintToolCall( calls.c_str(), calls.size() ); + } } } if( json.contains( "content" ) ) @@ -198,45 +201,48 @@ bool TracyLlmChat::Turn( TurnRole role, const nlohmann::json& json ) auto& content = json["content"].get_ref(); if( json["role"].get_ref() == "tool" ) { - ThinkScope( !roleChange ); - if( m_thinkOpen ) + if( think ) { - ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.5f, 0.5f, 0.5f, 1.f ) ); - if( content == ForgetMsg ) + ThinkScope( !roleChange ); + if( m_thinkOpen ) { - ImGui::TextUnformatted( ICON_FA_RECYCLE " Tool response removed to save context space" ); - m_subIdx++; + ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.5f, 0.5f, 0.5f, 1.f ) ); + if( content == ForgetMsg ) + { + ImGui::TextUnformatted( ICON_FA_RECYCLE " Tool response removed to save context space" ); + m_subIdx++; + } + else + { + auto& name = json["name"].get_ref(); + auto& id = json["tool_call_id"].get_ref(); + ImGui::PushID( m_subIdx++ ); + char buf[1024]; + snprintf( buf, sizeof( buf ), ICON_FA_REPLY " Tool response (%s/%s)...", name.c_str(), id.substr( 0, 8 ).c_str() ); + if( ImGui::TreeNode( buf ) ) + { + std::string parsed; + try + { + parsed = nlohmann::json::parse( content.c_str() ).dump( 2 ); + } + catch( nlohmann::json::exception& ) + { + parsed = content; + } + ImGui::PushFont( g_fonts.mono, FontNormal ); + ImGui::TextWrapped( "%s", parsed.c_str() ); + ImGui::PopFont(); + ImGui::TreePop(); + } + ImGui::PopID(); + } + ImGui::PopStyleColor(); } else { - auto& name = json["name"].get_ref(); - auto& id = json["tool_call_id"].get_ref(); - ImGui::PushID( m_subIdx++ ); - char buf[1024]; - snprintf( buf, sizeof( buf ), ICON_FA_REPLY " Tool response (%s/%s)...", name.c_str(), id.substr( 0, 8 ).c_str() ); - if( ImGui::TreeNode( buf ) ) - { - std::string parsed; - try - { - parsed = nlohmann::json::parse( content.c_str() ).dump( 2 ); - } - catch( nlohmann::json::exception& ) - { - parsed = content; - } - ImGui::PushFont( g_fonts.mono, FontNormal ); - ImGui::TextWrapped( "%s", parsed.c_str() ); - ImGui::PopFont(); - ImGui::TreePop(); - } - ImGui::PopID(); + m_subIdx++; } - ImGui::PopStyleColor(); - } - else - { - m_subIdx++; } } else diff --git a/profiler/src/profiler/TracyLlmChat.hpp b/profiler/src/profiler/TracyLlmChat.hpp index 117da148..fbc5b0bb 100644 --- a/profiler/src/profiler/TracyLlmChat.hpp +++ b/profiler/src/profiler/TracyLlmChat.hpp @@ -31,7 +31,7 @@ public: void Begin(); void End(); - bool Turn( TurnRole role, const nlohmann::json& json ); + bool Turn( TurnRole role, const nlohmann::json& json, bool think ); private: void NormalScope();