Skip to main content

marvin.fns.classify

Functions

classify

Classifies input data into one or more predefined labels using a language model. This function uses a language model to analyze the input data and assign it to the most appropriate label(s) from the provided sequence of labels or Enum class. Args: data: The input data to classify. Can be any type. labels: Either a sequence of possible labels (of type T) or an Enum class to classify the data into. If an Enum class is provided, its values will be used as the labels. multi_label: If False (default), returns a single label. If True, returns multiple labels as a list. instructions: Optional additional instructions to guide the classification. Used to provide specific guidance about how to interpret or classify the data. agent: Optional custom agent to use for classification. If not provided, the default agent will be used. thread: Optional thread for maintaining conversation context. Can be either a Thread object or a string thread ID. context: Optional dictionary of additional context to include in the task. handlers: Optional list of handlers to use for the task. Returns:
  • If labels is a Sequence[T]:
    • If multi_label is False: returns T
    • If multi_label is True: returns list[T]
  • If labels is an Enum class:
    • If multi_label is False: returns E (the Enum value)
    • If multi_label is True: returns list[E] (list of Enum values)
Examples:

classify_async

Asynchronously classifies input data into one or more predefined labels using a language model. This function uses a language model to analyze the input data and assign it to the most appropriate label(s) from the provided sequence of labels or Enum class. Args: data: The input data to classify. Can be any type. labels: Either a sequence of possible labels (of type T) or an Enum class to classify the data into. If an Enum class is provided, its values will be used as the labels. multi_label: If False (default), returns a single label. If True, returns multiple labels as a list. instructions: Optional additional instructions to guide the classification. Used to provide specific guidance about how to interpret or classify the data. agent: Optional custom agent to use for classification. If not provided, the default agent will be used. thread: Optional thread for maintaining conversation context. Can be either a Thread object or a string thread ID. context: Optional dictionary of additional context to include in the task. prompt: Optional prompt to use for the task. If not provided, the default prompt will be used. Returns:
  • If labels is a Sequence[T]:
    • If multi_label is False: returns T
    • If multi_label is True: returns list[T]
  • If labels is an Enum class:
    • If multi_label is False: returns E (the Enum value)
    • If multi_label is True: returns list[E] (list of Enum values)
Examples:

Parent Module: fns