Class: LLM::Tool
- Inherits:
-
Object
- Object
- LLM::Tool
- Extended by:
- Param
- Defined in:
- lib/llm/tool.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.
Defined Under Namespace
Modules: Param
Class Method Summary collapse
-
.description(desc
= nil) ⇒ String
Returns (or sets) the tool description.
-
.inherited(klass) ⇒
void
Registers the tool as a function when inherited.
-
.name(name = nil) ⇒
String
Returns (or sets) the tool name.
-
.registry ⇒
Array<LLM::Tool>
Returns all registered subclasses of LLM::Tool.
-
.params {|schema| ... } ⇒
LLM::Schema
Returns (or sets) tool parameters.
- .function ⇒ Object private
- .lock ⇒ Object private
Methods included from Param
Class Method Details
.description(desc = nil) ⇒ String
Returns (or sets) the tool description
67 68 69 70 71 |
# File 'lib/llm/tool.rb', line 67 def self.description(desc = nil) lock do desc ? function.description(desc) : function.description end end |
.inherited(klass) ⇒ void
This method returns an undefined value.
Registers the tool as a function when inherited
45 46 47 48 49 50 51 |
# File 'lib/llm/tool.rb', line 45 def self.inherited(klass) LLM.lock(:inherited) do klass.instance_eval { @__monitor ||= Monitor.new } klass.function.register(klass) klass.superclass.registry << klass end end |
.name(name = nil) ⇒ String
Returns (or sets) the tool name
57 58 59 60 61 |
# File 'lib/llm/tool.rb', line 57 def self.name(name = nil) lock do name ? function.name(name) : function.name end end |
.registry ⇒ Array<LLM::Tool>
Returns all registered subclasses of LLM::Tool
36 37 38 |
# File 'lib/llm/tool.rb', line 36 def self.registry @registry end |
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters
77 78 79 80 81 |
# File 'lib/llm/tool.rb', line 77 def self.params(&) lock do function.tap { _1.params(&) } 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.
85 86 87 88 89 |
# File 'lib/llm/tool.rb', line 85 def self.function lock do @function ||= LLM::Function.new(self) 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.
93 94 95 |
# File 'lib/llm/tool.rb', line 93 def self.lock(&) @__monitor.synchronize(&) end |