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.
- .function ⇒ Object private
-
.inherited(klass)
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 Param
Class Method Details
.description(desc = nil) ⇒ String
Returns (or sets) the tool description
58 59 60 61 62 |
# File 'lib/llm/tool.rb', line 58 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.
76 77 78 79 80 |
# File 'lib/llm/tool.rb', line 76 def self.function lock do @function ||= LLM::Function.new(self) end end |
.inherited(klass)
This method returns an undefined value.
Registers the tool as a function when inherited
37 38 39 40 41 42 |
# File 'lib/llm/tool.rb', line 37 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.
84 85 86 |
# File 'lib/llm/tool.rb', line 84 def self.lock(&) @__monitor.synchronize(&) end |
.name(name = nil) ⇒ String
Returns (or sets) the tool name
48 49 50 51 52 |
# File 'lib/llm/tool.rb', line 48 def self.name(name = nil) lock do name ? function.name(name) : function.name end end |
.params {|schema| ... } ⇒ LLM::Schema
Returns (or sets) tool parameters
68 69 70 71 72 |
# File 'lib/llm/tool.rb', line 68 def self.params(&) lock do function.tap { _1.params(&) } end end |