Class: Braintrust::Classifier::Block
- Inherits:
-
Object
- Object
- Braintrust::Classifier::Block
- Includes:
- Braintrust::Classifier
- Defined in:
- lib/braintrust/classifier.rb
Overview
Block-based classifier. Stores a Proc and delegates #call to it. Includes Classifier so it satisfies Classifier === checks. Exposes #call_parameters so KeywordFilter can introspect the block’s declared kwargs rather than Block#call’s **kwargs signature.
Constant Summary
Constants included from Braintrust::Classifier
Instance Attribute Summary collapse
- #name ⇒ String readonly
Instance Method Summary collapse
-
#call(**kwargs) ⇒ Array<Hash>
Normalized classification results.
-
#call_parameters ⇒ Array<Array>
Exposes the block’s parameter list so KeywordFilter can filter kwargs to match the block’s declared keywords.
-
#initialize(name: DEFAULT_NAME, &block) ⇒ Block
constructor
A new instance of Block.
Methods included from Braintrust::Classifier
Constructor Details
#initialize(name: DEFAULT_NAME, &block) ⇒ Block
Returns a new instance of Block.
134 135 136 137 138 139 140 141 |
# File 'lib/braintrust/classifier.rb', line 134 def initialize(name: DEFAULT_NAME, &block) @name = name params = block.parameters unless Internal::Callable::KeywordFilter.has_any_keywords?(params) || block.arity == 0 raise ArgumentError, "Classifier block must use keyword args (got arity #{block.arity})" end @block = block end |
Instance Attribute Details
#name ⇒ String (readonly)
129 130 131 |
# File 'lib/braintrust/classifier.rb', line 129 def name @name end |
Instance Method Details
#call(**kwargs) ⇒ Array<Hash>
Returns normalized classification results.
145 146 147 |
# File 'lib/braintrust/classifier.rb', line 145 def call(**kwargs) @block.call(**kwargs) end |
#call_parameters ⇒ Array<Array>
Exposes the block’s parameter list so KeywordFilter can filter kwargs to match the block’s declared keywords.
152 153 154 |
# File 'lib/braintrust/classifier.rb', line 152 def call_parameters @block.parameters end |