From 4969be344e2b5c6256efa78bb758d24e8a8e0fb8 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 29 Jun 2025 00:53:03 +0200 Subject: [PATCH] Use exact tokens count when available in server response. Note that this is not really exacy, as it includes system prompt reminder and possibly other input data that is dynamically injected. --- profiler/src/profiler/TracyLlm.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index ddb89866..42a3efa5 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -825,6 +825,12 @@ bool TracyLlm::OnResponse( const nlohmann::json& json ) if( done ) { + if( json.contains( "usage" ) ) + { + auto& usage = json["usage"]; + if( usage.contains( "total_tokens" ) ) m_usedCtx = usage["total_tokens"].get(); + } + bool isTool = false; auto& str = back["content"].get_ref(); if( !str.starts_with( "" ) )