Module: LLM::Backend
- Defined in:
- lib/scout/llm/backends/default.rb
Overview
Shared implementation for all LLM backends.
This file used to expose its API by doing extend Backend in each backend
module. That worked for simple overrides, but other backends (notably
OpenWebUI) started copying singleton methods from another backend.
Copying/binding singleton methods breaks Ruby's internal dispatch because
internal calls stay bound to the original receiver.
The supported/idiomatic way to share backend logic while allowing overrides is to keep the shared implementation as a module, and compose backends by building their singleton-method lookup chain:
class << self
prepend BackendSpecificMethods # overrides
include Backend::ClassMethods # shared implementation
end
With this arrangement, shared methods (like ask) can call overridable
methods (like query / format_tool_call) and Ruby will correctly dispatch
to the backend override.
Defined Under Namespace
Modules: ClassMethods Classes: BackendException
Class Method Summary collapse
-
.extended(base) ⇒ Object
Backwards-compatibility with the old pattern (
extend Backend). - .included(base) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
Backwards-compatibility with the old pattern (extend Backend).
We now recommend composing backends by manipulating their singleton class directly, but keeping these hooks makes the transition incremental.
633 634 635 |
# File 'lib/scout/llm/backends/default.rb', line 633 def self.extended(base) base.singleton_class.include(ClassMethods) end |
.included(base) ⇒ Object
637 638 639 |
# File 'lib/scout/llm/backends/default.rb', line 637 def self.included(base) base.extend(ClassMethods) end |