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 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 and returns a structured representation of the file system hierarchy.
61 62 63 64 65 66 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 61 def execute(tool_call, **opts) path = Pathname.new(tool_call.function.arguments.path || '.') structure = generate_structure(path) 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.
74 75 76 |
# File 'lib/ollama_chat/tools/directory_structure.rb', line 74 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 a path parameter for directory traversal.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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)' ), }, required: [] ) ) ) end |