Class: LLM::Tool
- Inherits:
-
Object
- Object
- LLM::Tool
- Defined in:
- lib/llm/tool.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.
Class Method Summary collapse
-
.inherited(klass) ⇒ void
Registers the tool as a function when inherited.
-
.name(name = nil) ⇒ String
Returns (or sets) the tool name.
-
.description(desc = nil) ⇒ String
Returns (or sets) the tool description.
-
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters.
-
.function ⇒ Object
private
-
.lock ⇒ Object
private
Class Method Details
.inherited(klass) ⇒ void
This method returns an undefined value.
Registers the tool as a function when inherited
25 26 27 28 29 30 |
# File 'lib/llm/tool.rb', line 25 def self.inherited(klass) LLM.lock(:inherited) do klass.instance_eval { @__monitor ||= Monitor.new } klass.function.register(klass) end end |
.name(name = nil) ⇒ String
Returns (or sets) the tool name
36 37 38 39 40 |
# File 'lib/llm/tool.rb', line 36 def self.name(name = nil) lock do function.tap { _1.name(name) } end end |
.description(desc = nil) ⇒ String
Returns (or sets) the tool description
46 47 48 49 50 |
# File 'lib/llm/tool.rb', line 46 def self.description(desc = nil) lock do function.tap { _1.description(desc) } end end |
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters
56 57 58 59 60 |
# File 'lib/llm/tool.rb', line 56 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.
64 65 66 67 68 |
# File 'lib/llm/tool.rb', line 64 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.
72 73 74 |
# File 'lib/llm/tool.rb', line 72 def self.lock(&) @__monitor.synchronize(&) end |