Class: RubyLLM::Test::CompleteParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/test/complete_parameters.rb

Overview

This class encapsulates all the parameters that are passed to the ‘complete` method of the wrapped provider. It stores the raw arguments and uses the wrapped provider’s actual method signature to expose named accessors for inspection in tests.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args:, kwargs:, block:, parameter_definitions:) ⇒ CompleteParameters

Returns a new instance of CompleteParameters.



16
17
18
19
20
21
# File 'lib/ruby_llm/test/complete_parameters.rb', line 16

def initialize(args:, kwargs:, block:, parameter_definitions:)
  @args = args
  @kwargs = kwargs
  @block = block
  @parameter_definitions = parameter_definitions
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *call_args) ⇒ Object



43
44
45
46
47
48
# File 'lib/ruby_llm/test/complete_parameters.rb', line 43

def method_missing(name, *call_args)
  return super unless call_args.empty?
  return self[name] if key?(name)

  super
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/ruby_llm/test/complete_parameters.rb', line 9

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



9
10
11
# File 'lib/ruby_llm/test/complete_parameters.rb', line 9

def block
  @block
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



9
10
11
# File 'lib/ruby_llm/test/complete_parameters.rb', line 9

def kwargs
  @kwargs
end

#parameter_definitionsObject (readonly)

Returns the value of attribute parameter_definitions.



9
10
11
# File 'lib/ruby_llm/test/complete_parameters.rb', line 9

def parameter_definitions
  @parameter_definitions
end

Class Method Details

.capture_from(provider, *args, **kwargs, &block) ⇒ Object



11
12
13
14
# File 'lib/ruby_llm/test/complete_parameters.rb', line 11

def self.capture_from(provider, *args, **kwargs, &block)
  parameters = provider.method(:complete).parameters
  new(args:, kwargs:, block:, parameter_definitions: parameters)
end

Instance Method Details

#[](name) ⇒ Object



27
28
29
30
31
32
# File 'lib/ruby_llm/test/complete_parameters.rb', line 27

def [](name)
  name = name.to_sym
  return block if name == :block

  positional_name_to_value[name] || kwargs[name]
end

#block_received?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_llm/test/complete_parameters.rb', line 23

def block_received?
  !block.nil?
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/ruby_llm/test/complete_parameters.rb', line 34

def key?(name)
  name = name.to_sym
  name == :block || positional_name_to_value.key?(name) || kwargs.key?(name)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/ruby_llm/test/complete_parameters.rb', line 50

def respond_to_missing?(name, include_private = false)
  key?(name) || super
end

#to_hObject



39
40
41
# File 'lib/ruby_llm/test/complete_parameters.rb', line 39

def to_h
  positional_name_to_value.merge(kwargs).merge(block: block)
end

#tool_classesObject



54
55
56
# File 'lib/ruby_llm/test/complete_parameters.rb', line 54

def tool_classes
  (kwargs[:tools] || {}).values.map(&:class)
end