Class: LLM::Tool
- Inherits:
-
Object
- Object
- LLM::Tool
- Defined in:
- lib/llm/shell/internal/llm.rb/lib/llm/tool.rb,
lib/llm/shell/tool.rb,
lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb
Overview
The LLM::Tool class represents a local tool that can be called by an LLM. Under the hood, it is a wrapper around LLM::Function but allows the definition of a function (also known as a tool) as a class.
Direct Known Subclasses
Shell::Tools::ReadFile, Shell::Tools::System, Shell::Tools::WriteFile
Defined Under Namespace
Class Method Summary collapse
-
.description(desc = nil) ⇒ String
Returns (or sets) the tool description.
- .function ⇒ Object private
-
.inherited(klass) ⇒ void
Registers the tool as a function when inherited.
- .lock ⇒ Object private
-
.name(name = nil) ⇒ String
Returns (or sets) the tool name.
-
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters.
Methods included from Patch
builtin?, disable!, enable!, enabled?
Methods included from Param
Class Method Details
.description(desc = nil) ⇒ String
Returns (or sets) the tool description
49 50 51 52 53 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 49 def self.description(desc = nil) lock do desc ? function.description(desc) : function.description end end |
.function ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 70 71 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 67 def self.function lock do @function ||= LLM::Function.new(self) end end |
.inherited(klass) ⇒ void
This method returns an undefined value.
Registers the tool as a function when inherited
28 29 30 31 32 33 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 28 def self.inherited(klass) LLM.lock(:inherited) do klass.instance_eval { @__monitor ||= Monitor.new } klass.function.register(klass) end end |
.lock ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 75 def self.lock(&) @__monitor.synchronize(&) end |
.name(name = nil) ⇒ String
Returns (or sets) the tool name
39 40 41 42 43 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 39 def self.name(name = nil) lock do name ? function.name(name) : function.name end end |
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters
59 60 61 62 63 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool.rb', line 59 def self.params(&) lock do function.tap { _1.params(&) } end end |