Class: Envoy::LLM

Inherits:
Object
  • Object
show all
Defined in:
lib/envoy/llm.rb

Instance Method Summary collapse

Constructor Details

#initialize(conversation:) ⇒ LLM

Returns a new instance of LLM.



3
4
5
# File 'lib/envoy/llm.rb', line 3

def initialize(conversation:)
  @conversation = conversation
end

Instance Method Details

#run(content:, tools:, instructions:) ⇒ Object

Drives a real RubyLLM turn via acts_as_chat. Yields [:delta, text] chunks.

NOTE: RubyLLM 1.16's ChatMethods#with_model keyword is assume_exists:, not assume_model_exists: — verified against the installed gem (lib/ruby_llm/active_record/chat_methods.rb and lib/ruby_llm/chat.rb).



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/envoy/llm.rb', line 12

def run(content:, tools:, instructions:)
  chat = @conversation
    .with_model(@conversation.resolved_model_id,
                provider: Envoy.config.provider,
                assume_exists: true)
    .with_instructions(instructions)
  chat = chat.with_tools(*tools) if tools.any?
  chat.ask(content) do |chunk|
    yield [ :delta, chunk.content ] if block_given? && chunk.content.present?
  end
end