Class: Phronomy::LLMAdapter::RubyLLM

Inherits:
Base
  • Object
show all
Defined in:
lib/phronomy/llm_adapter/ruby_llm.rb

Overview

Default LLMAdapter SPI implementation backed by RubyLLM.

The synchronous chat.ask / chat.complete calls are invoked through the framework-owned async bridge in Base, so adapter consumers do not need to manage OffloadPool themselves.

Examples:

Explicitly configuring this adapter

Phronomy.configure do |c|
  c.llm_adapter = Phronomy::LLMAdapter::RubyLLM.new
end

Instance Method Summary collapse

Methods inherited from Base

#complete_async, #stream_async

Instance Method Details

#complete(chat, message, config: {}) ⇒ Object

Delegates to chat.ask(message) or chat.complete when message is nil.

Passing nil for message is used by the ReAct loop for continuation turns where the user message has already been added to the chat history (for example after a Tool result).

Parameters:

  • chat (Object)

    RubyLLM chat session

  • message (String, nil)

    user message, or nil to continue the chat

  • config (Hash) (defaults to: {})

    invocation config (not used directly here)

Returns:

  • (Object)

    RubyLLM response



29
30
31
# File 'lib/phronomy/llm_adapter/ruby_llm.rb', line 29

def complete(chat, message, config: {})
  message ? chat.ask(message) : chat.complete
end

#stream(chat, message, config: {}) {|chunk| ... } ⇒ Object

Delegates to chat.ask(message) { |chunk| ... } or chat.complete(&block) when message is nil.

Parameters:

  • chat (Object)

    RubyLLM chat session

  • message (String, nil)

    user message, or nil to continue the chat

  • config (Hash) (defaults to: {})

    invocation config

Yields:

  • (chunk)

    streaming chunk forwarded from RubyLLM

Returns:

  • (Object)

    RubyLLM response



42
43
44
# File 'lib/phronomy/llm_adapter/ruby_llm.rb', line 42

def stream(chat, message, config: {}, &block)
  message ? chat.ask(message, &block) : chat.complete(&block)
end