Class: Ask::Agent::StreamTransforms::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/agent/stream_transforms/base.rb

Overview

Base class for stream transforms that process Chunks.

Each transform receives every chunk from the LLM stream and can modify, filter, or buffer it. To emit zero or more transformed chunks, yield to the provided block.

Examples:

A simple pass-through transform

class NoOp < Base
  def call(chunk, &block)
    yield chunk
  end
end

A transform that drops thinking-only chunks

class DropThinking < Base
  def call(chunk, &block)
    yield chunk unless chunk.thinking? && chunk.content.to_s.empty?
  end
end

Direct Known Subclasses

ExtractJson, TextBuffer, ThinkingSeparator

Instance Method Summary collapse

Instance Method Details

#call(chunk) {|Ask::Chunk| ... } ⇒ Object

Process a single chunk from the LLM stream.

Parameters:

  • chunk (Ask::Chunk)

    the raw chunk from the LLM provider

Yields:

  • (Ask::Chunk)

    zero or more transformed chunks



30
31
32
# File 'lib/ask/agent/stream_transforms/base.rb', line 30

def call(chunk, &block)
  yield chunk
end

#finish {|Ask::Chunk| ... } ⇒ Object

Called once when the stream finishes, giving buffering transforms a chance to flush any remaining state. The default is a no-op.

Yields:

  • (Ask::Chunk)

    final chunks to emit



38
39
40
# File 'lib/ask/agent/stream_transforms/base.rb', line 38

def finish(&block)
  # no-op
end