Class: Engram::Adapters::RubyLLMCompletion

Inherits:
Object
  • Object
show all
Includes:
Ports::Completion
Defined in:
lib/engram/adapters/ruby_llm_completion.rb

Overview

Completion backed by RubyLLM structured output. Requires the host app to add the ‘ruby_llm` gem and configure credentials. Referenced only at call time.

NOTE: exercised via integration tests, not the unit suite (which uses FakeCompletion).

Instance Method Summary collapse

Constructor Details

#initialize(model: nil) ⇒ RubyLLMCompletion

Returns a new instance of RubyLLMCompletion.



12
13
14
# File 'lib/engram/adapters/ruby_llm_completion.rb', line 12

def initialize(model: nil)
  @model = model
end

Instance Method Details

#complete(system:, user:, schema:) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/engram/adapters/ruby_llm_completion.rb', line 16

def complete(system:, user:, schema:)
  ensure_ruby_llm!
  chat = @model ? RubyLLM.chat(model: @model) : RubyLLM.chat
  chat.with_instructions(system) if system
  response = chat.with_schema(schema).ask(user)
  coerce(response.content)
end