Class: OllamaChat::Tools::DirectoryStructure
- Inherits:
-
Object
- Object
- OllamaChat::Tools::DirectoryStructure
- Includes:
- Ollama
- Defined in:
- lib/ollama_chat/tools/directory_structure.rb
Overview
A tool for retrieving directory structure and file hierarchy.
This tool allows the chat client to retrieve the directory structure and file hierarchy for a given path. It integrates with the Ollama tool calling system to provide detailed directory information to the language model.
The tool supports traversing directories up to a specified depth and returns a structured representation of the file system hierarchy.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Returns the name of the tool.
Instance Method Summary collapse
-
#execute(tool_call, **opts) ⇒ String
Executes the directory structure retrieval operation.
-
#initialize ⇒ OllamaChat::Tools::DirectoryStructure
constructor
Initializes a new directory_structure tool instance.
-
#to_hash ⇒ Hash
Converts the tool to a hash representation.
-
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for retrieving directory structure.
Constructor Details
#initialize ⇒ OllamaChat::Tools::DirectoryStructure
Initializes a new directory_structure tool instance.
15 16 17 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 15 def initialize @name = 'directory_structure' end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the tool.
22 23 24 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 22 def name @name end |
Instance Method Details
#execute(tool_call, **opts) ⇒ String
Executes the directory structure retrieval operation.
This method traverses the directory structure starting from the specified path up to the given depth and returns a structured representation of the file system hierarchy.
65 66 67 68 69 70 71 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 65 def execute(tool_call, **opts) path = Pathname.new(tool_call.function.arguments.path || '.') depth = (tool_call.function.arguments.depth || 2).to_i structure = generate_structure(path, depth) structure.to_json end |
#to_hash ⇒ Hash
Converts the tool to a hash representation.
This method provides a standardized way to serialize the tool definition for use in tool calling systems.
79 80 81 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 79 def to_hash tool.to_hash end |
#tool ⇒ Ollama::Tool
Creates and returns a tool definition for retrieving directory structure.
This method constructs the function signature that describes what the tool does, its parameters, and required fields. The tool accepts path and depth parameters for directory traversal.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 31 def tool Tool.new( type: 'function', function: Tool::Function.new( name:, description: 'Retrieve the directory structure and file hierarchy for a given path', parameters: Tool::Function::Parameters.new( type: 'object', properties: { path: Tool::Function::Parameters::Property.new( type: 'string', description: 'Path to directory to list (defaults to current directory)' ), depth: Tool::Function::Parameters::Property.new( type: 'integer', description: 'Depth of directory traversal (defaults to 2)' ) }, required: [] ) ) ) end |