Module: LLM::Tool::Param

Included in:
LLM::Tool
Defined in:
lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb

Overview

The LLM::Tool::Param module extends the LLM::Tool class with a “param” method that can define a parameter for simple types. For complex types, use LLM::Tool.params instead.

Examples:

class Greeter < LLM::Tool
  name "greeter"
  description "Greets the user"
  param :name, String, "The user's name", required: true

  def call(name:)
    puts "Hello, #{name}!"
  end
end

Defined Under Namespace

Modules: Utils

Instance Method Summary collapse

Instance Method Details

#param(name, type, description, options = {}) ⇒ Object

Parameters:

  • name (Symbol)

    The name of a parameter

  • type (Class, Symbol)

    The parameter type (eg String)

  • description (String)

    The description of a property

  • options (Hash) (defaults to: {})

    A hash of options for the parameter

Options Hash (options):

  • :required (Boolean)

    Whether or not the parameter is required

  • :default (Object)

    The default value for a given property

  • :enum (Array<String>)

    One or more possible values for a param



36
37
38
39
40
41
42
43
44
# File 'lib/llm/shell/internal/llm.rb/lib/llm/tool/param.rb', line 36

def param(name, type, description, options = {})
  lock do
    function.params do |schema|
      leaf = schema.public_send(Utils.resolve(type))
      leaf = Utils.setup(leaf, description, options)
      schema.object(name => leaf)
    end
  end
end