Class: LastLLM::Tool
- Inherits:
-
Object
- Object
- LastLLM::Tool
- Defined in:
- lib/last_llm/tool.rb
Overview
Tool class for defining callable functions that can be used with LLM providers
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#call(params) ⇒ Hash
Call the tool with the provided parameters.
-
#initialize(name:, description:, parameters:, function:) ⇒ Tool
constructor
Initialize a new tool.
Constructor Details
#initialize(name:, description:, parameters:, function:) ⇒ Tool
Initialize a new tool
16 17 18 19 20 21 22 23 |
# File 'lib/last_llm/tool.rb', line 16 def initialize(name:, description:, parameters:, function:) validate_initialization_params(name, description, parameters, function) @name = name @description = description @parameters = parameters @function = function end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/last_llm/tool.rb', line 9 def description @description end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
9 10 11 |
# File 'lib/last_llm/tool.rb', line 9 def function @function end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/last_llm/tool.rb', line 9 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/last_llm/tool.rb', line 9 def parameters @parameters end |
Instance Method Details
#call(params) ⇒ Hash
Call the tool with the provided parameters
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/last_llm/tool.rb', line 28 def call(params) # Convert string keys to symbols params = symbolize_keys(params) # Validate parameters against the schema validate_parameters(params) # Convert parameter types if needed converted_params = convert_parameter_types(params) # Execute the function function.call(converted_params) end |