Module: DSPy::Callbacks::ClassMethods

Defined in:
lib/dspy/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#create_after_callback(method_name, wrap: true) ⇒ Object

Creates an after callback hook for the specified method

Parameters:

  • method_name (Symbol)

    the method to add callback support to



65
66
67
68
69
# File 'lib/dspy/callbacks.rb', line 65

def create_after_callback(method_name, wrap: true)
  mark_method_has_callbacks(method_name, wrap: wrap)
  ensure_callback_method_defined(:after, method_name)
  wrap_method_with_callbacks(method_name) if wrap
end

#create_around_callback(method_name, wrap: true) ⇒ Object

Creates an around callback hook for the specified method

Parameters:

  • method_name (Symbol)

    the method to add callback support to



74
75
76
77
78
# File 'lib/dspy/callbacks.rb', line 74

def create_around_callback(method_name, wrap: true)
  mark_method_has_callbacks(method_name, wrap: wrap)
  ensure_callback_method_defined(:around, method_name)
  wrap_method_with_callbacks(method_name) if wrap
end

#create_before_callback(method_name, wrap: true) ⇒ Object

Configures a method to expose before callbacks.

Creates a before callback hook for the specified method

Parameters:

  • method_name (Symbol)

    the target method.

  • wrap (Boolean) (defaults to: true)

    When true (default), the method is transparently wrapped so callbacks run automatically on every invocation. Pass false when you plan to trigger callbacks manually (e.g., to interleave custom spans or thread management). Manual targets are never re-wrapped, so execution order stays entirely in your control.

  • method_name (Symbol)

    the method to add callback support to



56
57
58
59
60
# File 'lib/dspy/callbacks.rb', line 56

def create_before_callback(method_name, wrap: true)
  mark_method_has_callbacks(method_name, wrap: wrap)
  ensure_callback_method_defined(:before, method_name)
  wrap_method_with_callbacks(method_name) if wrap
end