diff --git a/profiler/src/llm/tools.json b/profiler/src/llm/tools.json index 323287c2..b1f568a1 100644 --- a/profiler/src/llm/tools.json +++ b/profiler/src/llm/tools.json @@ -117,7 +117,7 @@ "type": "function", "function": { "name": "source_file", - "description": "Retrieve the source file contents.", + "description": "Retrieve the source file contents around given line.", "parameters": { "type": "object", "properties": { @@ -127,7 +127,11 @@ }, "line": { "type": "integer", - "description": "Line number that should be retrieved." + "description": "Target line number." + }, + "context": { + "type": "integer", + "description": "How many lines to display before and after the target line." } }, "required": ["file", "line"] diff --git a/profiler/src/profiler/TracyLlmTools.cpp b/profiler/src/profiler/TracyLlmTools.cpp index 1683e053..22b13ef5 100644 --- a/profiler/src/profiler/TracyLlmTools.cpp +++ b/profiler/src/profiler/TracyLlmTools.cpp @@ -163,7 +163,7 @@ TracyLlmTools::ToolReply TracyLlmTools::HandleToolCalls( const std::string& tool } else if( tool == "source_file" ) { - return { .reply = SourceFile( Param( "file" ), ParamU32( "line" ) ) }; + return { .reply = SourceFile( Param( "file" ), ParamU32( "line" ), ParamOptU32( "context", 5 ) ) }; } return { .reply = "Unknown tool call: " + tool }; } @@ -760,7 +760,7 @@ std::string TracyLlmTools::SearchManual( const std::string& query, TracyLlmApi& return json.dump( 2, ' ', false, nlohmann::json::error_handler_t::replace ); } -std::string TracyLlmTools::SourceFile( const std::string& file, uint32_t line ) const +std::string TracyLlmTools::SourceFile( const std::string& file, uint32_t line, uint32_t context ) const { if( line == 0 ) return "Error: Source file line number must be greater than 0."; @@ -777,7 +777,7 @@ std::string TracyLlmTools::SourceFile( const std::string& file, uint32_t line ) uint32_t minLine = line; uint32_t maxLine = line+1; - while( minLine > 0 || maxLine < lines.size() ) + while( context > 0 && ( minLine > 0 || maxLine < lines.size() ) ) { if( minLine > 0 ) { @@ -791,6 +791,7 @@ std::string TracyLlmTools::SourceFile( const std::string& file, uint32_t line ) if( size >= maxSize ) break; maxLine++; } + context--; } nlohmann::json json = { diff --git a/profiler/src/profiler/TracyLlmTools.hpp b/profiler/src/profiler/TracyLlmTools.hpp index b30fe5af..b202464e 100644 --- a/profiler/src/profiler/TracyLlmTools.hpp +++ b/profiler/src/profiler/TracyLlmTools.hpp @@ -61,7 +61,7 @@ private: std::string SearchWeb( std::string query ); std::string GetWebpage( const std::string& url ); std::string SearchManual( const std::string& query, TracyLlmApi& api, bool hasEmbeddingsModel ); - std::string SourceFile( const std::string& file, uint32_t line ) const; + std::string SourceFile( const std::string& file, uint32_t line, uint32_t context ) const; void ManualEmbeddingsWorker( TracyLlmApi& api );