diff --git a/profiler/src/profiler/TracyLlmChat.cpp b/profiler/src/profiler/TracyLlmChat.cpp index df0b92fd..8cb2556c 100644 --- a/profiler/src/profiler/TracyLlmChat.cpp +++ b/profiler/src/profiler/TracyLlmChat.cpp @@ -288,8 +288,49 @@ bool TracyLlmChat::Turn( TurnRole role, const nlohmann::json& json, Think think, ThinkScope( !roleChange || json.contains( "content" ) ); if( m_thinkOpen ) { - auto calls = json["tool_calls"].dump( 2 ); - PrintToolCall( calls.c_str(), calls.size() ); + ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.5f, 0.5f, 0.5f, 1.f ) ); + if( json.contains( "reasoning_content" ) ) ImGui::Spacing(); + bool first = true; + for( auto& call : json["tool_calls"] ) + { + if( call.contains( "id" ) && call.contains( "function" ) ) + { + auto& function = call["function"]; + if( function.contains( "name" ) ) + { + if( first ) first = false; + else ImGui::Spacing(); + + auto& name = function["name"].get_ref(); + auto& id = call["id"].get_ref(); + + ImGui::TextWrapped( ICON_FA_TOOLBOX " Tool call (%s/%s)…", name.c_str(), id.substr( 0, 8 ).c_str() ); + if( function.contains( "arguments" ) ) + { + try + { + auto args = nlohmann::json::parse( function["arguments"].get_ref() ); + if( !args.empty() ) + { + ImGui::Indent(); + for( auto& [key, value] : args.items() ) + { + ImGui::Text( "%s: %s", key.c_str(), value.dump().c_str() ); + } + ImGui::Unindent(); + } + } + catch( nlohmann::json::exception& ) + { + ImGui::Indent(); + ImGui::TextWrapped( "%s", function["arguments"].get_ref().c_str() ); + ImGui::Unindent(); + } + } + } + } + } + ImGui::PopStyleColor(); } } } @@ -348,13 +389,4 @@ void TracyLlmChat::PrintThink( const char* str, size_t size ) ImGui::PopStyleColor(); } -void TracyLlmChat::PrintToolCall( const char* str, size_t size ) -{ - ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.5f, 0.5f, 0.5f, 1.f ) ); - ImGui::PushFont( g_fonts.mono, FontNormal ); - ImGui::TextWrapped( "%.*s", (int)size, str ); - ImGui::PopFont(); - ImGui::PopStyleColor(); -} - } diff --git a/profiler/src/profiler/TracyLlmChat.hpp b/profiler/src/profiler/TracyLlmChat.hpp index f80dae7c..ab87f6c2 100644 --- a/profiler/src/profiler/TracyLlmChat.hpp +++ b/profiler/src/profiler/TracyLlmChat.hpp @@ -45,7 +45,6 @@ private: void ThinkScope( bool spacing = false ); void PrintThink( const char* str, size_t size ); - void PrintToolCall( const char* str, size_t size ); float* m_width; float m_maxWidth;