Module: Braintrust::Classifier
- Included in:
- Block
- Defined in:
- lib/braintrust/classifier.rb
Overview
Classifier wraps a classification function that categorizes and labels eval outputs.
Unlike scorers (which return numeric 0-1 values), classifiers return structured Classification items with an id and optional label and metadata.
Use inline with a block (keyword args):
classifier = Classifier.new("category") { |output:| {name: "category", id: "greeting", label: "Greeting"} }
Or include in a class and define #call with keyword args:
class CategoryClassifier
include Braintrust::Classifier
def call(output:)
{name: "category", id: "greeting", label: "Greeting"}
end
end
Classifiers may return a single Classification hash, an Array of them, or nil (meaning no classifications for this case).
Defined Under Namespace
Modules: Callable Classes: Block
Constant Summary collapse
- DEFAULT_NAME =
"classifier"
Class Method Summary collapse
- .included(base) ⇒ Object
-
.new(name = nil, &block) ⇒ Classifier::Block
Create a block-based classifier.
Class Method Details
.included(base) ⇒ Object
29 30 31 |
# File 'lib/braintrust/classifier.rb', line 29 def self.included(base) base.include(Callable) end |
.new(name = nil, &block) ⇒ Classifier::Block
Create a block-based classifier.
42 43 44 |
# File 'lib/braintrust/classifier.rb', line 42 def self.new(name = nil, &block) Block.new(name: name || DEFAULT_NAME, &block) end |