Class: LLM::Transformer
- Inherits:
-
Object
- Object
- LLM::Transformer
- 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
Defined Under Namespace
Classes: Null
Instance Attribute Summary collapse
- #ctx ⇒ LLM::Context readonly
Instance Method Summary collapse
- #initialize(ctx) ⇒ LLM::Transformer constructor
- #call(message:, **opts) ⇒ LLM::Message abstract
Constructor Details
#initialize(ctx) ⇒ LLM::Transformer
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
Instance Method Details
#call(message:, **opts) ⇒ LLM::Message
This method is abstract.
37 38 39 |
# File 'lib/llm/transformer.rb', line 37 def call(message:, **opts) raise NotImplementedError end |