Class: LLM::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/transformer.rb,
lib/llm/transformer/null.rb

Overview

LLM::Transformer is the superclass for message transformers in llm.rb.

A transformer is bound to a context and rewrites a single message before it is sent to the provider. Each subclass implements a different transformation: it takes a message in #call and returns a message. Null is a no-op (the default).

A transformer may mutate the message in place or return a new one. Either way, the returned message is what gets sent.

Direct Known Subclasses

Null

Defined Under Namespace

Classes: Null

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ LLM::Transformer

Parameters:



26
27
28
# File 'lib/llm/transformer.rb', line 26

def initialize(ctx)
  @ctx = LLM::Agent === ctx ? ctx.instance_variable_get(:@ctx) : ctx
end

Instance Attribute Details

#ctxLLM::Context (readonly)

Returns:



21
22
23
# File 'lib/llm/transformer.rb', line 21

def ctx
  @ctx
end

Instance Method Details

#call(message:, **opts) ⇒ LLM::Message

This method is abstract.

Parameters:

  • message (LLM::Message)

    The message to transform

  • opts (Hash)

    Per-call options

Returns:

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/llm/transformer.rb', line 37

def call(message:, **opts)
  raise NotImplementedError
end