Module: RSpec::LLM::DSL::GroupMethods

Defined in:
lib/rspec/llm/dsl.rb

Overview

Class-level helper exposed inside ‘describe_llm` blocks.

Instance Method Summary collapse

Instance Method Details

#evaluate(name, prompt:, expect:, client: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/llm/dsl.rb', line 15

def evaluate(name, prompt:, expect:, client: nil)
  it(name) do
    adapter = client ? RSpec::LLM::Adapters::Base.wrap(client) : RSpec::LLM.client
    raise RSpec::LLM::Error, "No LLM client configured" if adapter.nil?

    response = adapter.chat(prompt)
    Array(expect).each do |matcher|
      ::RSpec::Expectations::PositiveExpectationHandler.handle_matcher(response, matcher)
    end
  end
end