@@ -544,6 +544,65 @@ def create(
544544 return p
545545
546546
547+ class ClassifierBuilder :
548+ """Builder to create a classifier in Braintrust."""
549+
550+ def __init__ (self , project : "Project" ):
551+ self .project = project
552+ self ._task_counter = 0
553+
554+ def create (
555+ self ,
556+ * ,
557+ handler : Callable [..., Any ],
558+ name : str | None = None ,
559+ slug : str | None = None ,
560+ description : str | None = None ,
561+ parameters : Any = None ,
562+ returns : Any = None ,
563+ if_exists : IfExists | None = None ,
564+ metadata : Metadata | None = None ,
565+ tags : Sequence [str ] | None = None ,
566+ ) -> CodeFunction :
567+ """Creates a classifier.
568+
569+ Args:
570+ handler: The function that is called when the classifier is used.
571+ name: The name of the classifier.
572+ slug: A unique identifier for the classifier.
573+ description: The description of the classifier.
574+ parameters: The classifier's input schema, as a Pydantic model.
575+ returns: The classifier's output schema, as a Pydantic model.
576+ if_exists: What to do if the classifier already exists.
577+ metadata: Custom metadata to attach to the classifier.
578+ tags: A list of tags for the classifier.
579+ """
580+ self ._task_counter += 1
581+ if name is None or len (name ) == 0 :
582+ if handler .__name__ and handler .__name__ != "<lambda>" :
583+ name = handler .__name__
584+ else :
585+ name = f"Classifier { self ._task_counter } "
586+ if slug is None or len (slug ) == 0 :
587+ slug = slugify .slugify (name )
588+
589+ f = CodeFunction (
590+ project = self .project ,
591+ handler = handler ,
592+ name = name ,
593+ slug = slug ,
594+ type_ = "classifier" ,
595+ description = description ,
596+ parameters = parameters ,
597+ returns = returns ,
598+ if_exists = if_exists ,
599+ metadata = metadata ,
600+ tags = tags ,
601+ )
602+ self .project .add_code_function (f )
603+ return f
604+
605+
547606class Project :
548607 """A handle to a Braintrust project."""
549608
@@ -553,6 +612,7 @@ def __init__(self, name: str):
553612 self .prompts = PromptBuilder (self )
554613 self .parameters = ParametersBuilder (self )
555614 self .scorers = ScorerBuilder (self )
615+ self .classifiers = ClassifierBuilder (self )
556616
557617 self ._publishable_code_functions : list [CodeFunction ] = []
558618 self ._publishable_prompts : list [CodePrompt ] = []
0 commit comments