Module: Axn::RubyLLM::RSpec::Helpers

Defined in:
lib/axn/ruby_llm/rspec.rb

Instance Method Summary collapse

Instance Method Details

#stub_axn_ruby_llm(response:, model: nil, schema: nil, input_tokens: nil, output_tokens: nil, cost: nil) ⇒ Object

Stubs RubyLLM so that Ask returns a canned response.

Usage in a spec:

stub_axn_ruby_llm(response: "Here is a summary.")
stub_axn_ruby_llm(response: { "key" => "value" })  # auto-JSON-serialized for json: true calls
stub_axn_ruby_llm(response: { "k" => "v" }, schema: MySchema) # Hash passed through unparsed
stub_axn_ruby_llm(response: "...", input_tokens: 100, output_tokens: 50, cost: 0.0023)

Returns the chat instance double for further assertions if needed.



18
19
20
21
22
23
24
# File 'lib/axn/ruby_llm/rspec.rb', line 18

def stub_axn_ruby_llm(response:, model: nil, schema: nil, input_tokens: nil, output_tokens: nil, cost: nil)
  resolved_model_id = model || Axn::RubyLLM.configuration.default_model
  llm_message = _stub_axn_ruby_llm_message(response, resolved_model_id, input_tokens, output_tokens, schema:)
  chat_instance = _stub_axn_ruby_llm_chat(model, llm_message, schema:)
  _stub_axn_ruby_llm_cost(llm_message, resolved_model_id, cost)
  chat_instance
end