From e293f87a8ae2d49aab3365c3d13e8dd1d8ce49ac Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 16 May 2025 00:09:59 +0200 Subject: [PATCH] Adapt the wikipedia page cut-off to the available context size. --- profiler/src/profiler/TracyLlm.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index b7b3c878..b9a1c943 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -811,7 +811,13 @@ std::string TracyLlm::HandleToolCalls( const std::string& name, const std::vecto { if( args.empty() ) return "Missing page name argument"; auto res = FetchWebPage( "https://en.wikipedia.org/w/rest.php/v1/page/" + args[0] ); - if( res.size() > 10 * 1024 ) res = res.substr( 0, 10 * 1024 ); + + // Limit the size of the response to avoid exceeding the context size + // Assume average token size is 4 bytes. Make space for 3 articles to be retrieved. + const auto ctxSize = std::min( m_models[m_modelIdx].ctxSize, s_config.llmContext ); + const auto maxSize = ( ctxSize * 4 ) / 3; + + if( res.size() > maxSize ) res = res.substr( 0, maxSize ); return res; } return "Unknown tool call: " + name;