Module: Braintrust::Task

Included in:
Block
Defined in:
lib/braintrust/task.rb

Overview

Task wraps a callable that processes inputs.

Use inline with a block (keyword args):

task = Task.new("my_task") { |input:| process(input) }

Or include in a class and define #call with keyword args:

class MyTask
  include Braintrust::Task

  def call(input:)
    process(input)
  end
end

Legacy callables with 1 positional param are auto-wrapped for backwards compatibility but emit a deprecation warning.

Defined Under Namespace

Modules: Callable Classes: Block

Constant Summary collapse

DEFAULT_NAME =
"task"

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Parameters:

  • base (Class)

    the class including Task



26
27
28
# File 'lib/braintrust/task.rb', line 26

def self.included(base)
  base.include(Callable)
end

.new(name = nil, &block) ⇒ Task::Block

Create a block-based task.

Parameters:

  • name (String, nil) (defaults to: nil)

    optional name (defaults to “task”)

  • block (Proc)

    the task implementation; declare only the keyword args you need (e.g. |input:|). Extra kwargs passed by the caller are filtered out automatically.

Returns:

Raises:

  • (ArgumentError)

    if the block has unsupported arity



38
39
40
# File 'lib/braintrust/task.rb', line 38

def self.new(name = nil, &block)
  Block.new(name: name || DEFAULT_NAME, &block)
end