Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ jobs:
- "3.3"
- "3.4"
- "4.0"

ruby_llm:
- "1.5"
- "1.6"
- "1.10"
- "1.13"
- "1.14"
- "current"
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/ruby_llm_${{ matrix.ruby_llm }}.gemfile
BUNDLE_PATH_RELATIVE_TO_CWD: true
steps:
- uses: actions/checkout@v6
- name: Set up Ruby
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/_yardoc/
/coverage/
/doc/
/gemfiles/*.lock
/pkg/
/spec/reports/
/tmp/
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins:
AllCops:
TargetRubyVersion: 3.3
Exclude:
- "gemfiles/**/*"
- "ruby_llm-test.gemspec"
- "Rakefile"
- "vendor/**/*"
Expand All @@ -15,6 +16,13 @@ AllCops:
Layout/SpaceInsideArrayLiteralBrackets:
EnforcedStyle: space

Metrics/ClassLength:
Exclude:
- "test/**/*"
Metrics/MethodLength:
Exclude:
- "test/**/*"

Style/StringLiterals:
EnforcedStyle: double_quotes
Style/StringLiteralsInInterpolation:
Expand Down
25 changes: 25 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

appraise "ruby_llm-1.5" do
gem "ruby_llm", "~> 1.5.0"
end

appraise "ruby_llm-1.6" do
gem "ruby_llm", "~> 1.6.0"
end

appraise "ruby_llm-1.10" do
gem "ruby_llm", "~> 1.10.0"
end

appraise "ruby_llm-1.13" do
gem "ruby_llm", "~> 1.13.0"
end

appraise "ruby_llm-1.14" do
gem "ruby_llm", "~> 1.14.0"
end

appraise "ruby_llm-current" do
gem "ruby_llm"
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
gemspec

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ PATH
remote: .
specs:
ruby_llm-test (0.1.0)
ruby_llm (>= 1.14.0)
ruby_llm (>= 1.5.0)

GEM
remote: https://gem.coop/
specs:
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.3)
base64 (0.3.0)
docile (1.4.1)
Expand Down Expand Up @@ -78,6 +82,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
thor (1.5.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
Expand All @@ -89,6 +94,7 @@ PLATFORMS
ruby

DEPENDENCIES
appraisal (~> 2.5)
minitest (~> 6.0)
rake (~> 13.0)
rubocop (~> 1.86)
Expand All @@ -97,4 +103,4 @@ DEPENDENCIES
simplecov (~> 0.22)

BUNDLED WITH
4.0.10
4.0.10
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_1.10.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm", "~> 1.10.0"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_1.13.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm", "~> 1.13.0"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_1.14.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm", "~> 1.14.0"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_1.5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm", "~> 1.5.0"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_1.6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm", "~> 1.6.0"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
16 changes: 16 additions & 0 deletions gemfiles/ruby_llm_current.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by Appraisal

source "https://gem.coop"

gem "ruby_llm"

group :development, :test do
gem "appraisal", "~> 2.5"
gem "minitest", "~> 6.0"
gem "rake", "~> 13.0"
gem "rubocop", "~> 1.86"
gem "rubocop-minitest", "~> 0.39"
gem "simplecov", "~> 0.22"
end

gemspec path: "../"
70 changes: 54 additions & 16 deletions lib/ruby_llm/test/complete_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,65 @@

module RubyLLM
module Test
# This class encapsulates all the parameters that are passed to the `complete` method of the `Test` class. It
# serves as a structured way to manage and access these parameters throughout the testing process.
# 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.
class CompleteParameters
attr_reader :messages, :tools, :temperature, :model, :params, :headers, :schema, :thinking, :tool_prefs, :block

def initialize(messages:, tools:, temperature:, model:, params:, # rubocop:disable Metrics/ParameterLists
headers:, schema:, thinking:, tool_prefs:, block:)
@messages = messages
@tools = tools
@temperature = temperature
@model = model
@params = params
@headers = headers
@schema = schema
@thinking = thinking
@tool_prefs = tool_prefs
attr_reader :args, :kwargs, :block, :parameter_definitions

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

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

def block_received?
!@block.nil?
!block.nil?
end

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

positional_name_to_value[name] || kwargs[name]
end

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

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

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

super
end

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

private

def positional_name_to_value
@positional_name_to_value ||= begin
positional_names = parameter_definitions
.select { |parameter| %i[req opt].include?(parameter.first) }
.map(&:last)

positional_names.each_with_index.to_h { |param_name, index| [ param_name, args[index] ] }
end
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lib/ruby_llm/test/test_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ class TestProvider < SimpleDelegator

attr_reader :complete_calls

def_delegators :last_call, :messages, :tools, :temperature, :model, :params, :headers, :schema, :thinking,
:tool_prefs, :block_received?
def_delegators :last_call, :messages, :block_received?

def initialize(provider, test_harness = RubyLLM::Test)
super(provider)
@test_harness = test_harness
@complete_calls = []
end

def complete(messages, tools:, temperature:, model:, params: {}, # rubocop:disable Metrics/ParameterLists
headers: {}, schema: nil, thinking: nil, tool_prefs: nil, &block)
@complete_calls << CompleteParameters.new(messages:, tools:, temperature:, model:, params:, headers:, schema:,
thinking:, tool_prefs:, block:)
raise Errors::NoResponseProvidedError, messages if @test_harness.responses_empty?
def complete(...)
call = CompleteParameters.capture_from(__getobj__, ...)
@complete_calls << call
raise Errors::NoResponseProvidedError, call.messages if @test_harness.responses_empty?

response = @test_harness.next_response
return response if response.is_a?(Message)
Expand Down
2 changes: 1 addition & 1 deletion ruby_llm-test.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Gem::Specification.new do |spec|

spec.files = Dir["lib/**/*", "LICENSE.txt", "README.md"]

spec.add_dependency "ruby_llm", ">= 1.14.0"
spec.add_dependency "ruby_llm", ">= 1.5.0"
end
Loading
Loading