fabricatio_capabilities.capabilities.order

Module for the Ordering class which provides functionalities to order sequences based on requirements.

Classes

Ordering

Class providing methods to order sequences either directly via language model or by scores.

Functions

is_list_str(→ TypeGuard[List[str]])

Check if the input is a list of strings.

is_list_briefing(...)

Check if the input is a list of WithBriefing objects.

Module Contents

fabricatio_capabilities.capabilities.order.is_list_str(sq: Any) TypeGuard[List[str]]

Check if the input is a list of strings.

Parameters:

sq (Any) – Input to be validated.

Returns:

True if input is a list of strings, False otherwise.

Return type:

TypeGuard[List[str]]

fabricatio_capabilities.capabilities.order.is_list_briefing(sq: Any) TypeGuard[List[fabricatio_core.models.generic.WithBriefing]]

Check if the input is a list of WithBriefing objects.

Parameters:

sq (Any) – Input to be validated.

Returns:

True if input is a list of WithBriefing objects, False otherwise.

Return type:

TypeGuard[List[WithBriefing]]

class fabricatio_capabilities.capabilities.order.Ordering

Bases: fabricatio_capabilities.capabilities.rating.Rating

Class providing methods to order sequences either directly via language model or by scores.

async order_string(seq: List[str], requirement: str, reverse: bool = False, **kwargs: Unpack[fabricatio_core.models.kwargs_types.ValidateKwargs[List[str]]]) List[str] | None

Orders a list of strings based on a given requirement using a language model.

Parameters:
  • seq (List[str]) – The input sequence to be ordered.

  • requirement (str) – The requirement string guiding the ordering.

  • reverse (bool) – Whether to reverse the order. Defaults to False.

  • **kwargs – Additional keyword arguments.

Returns:

Ordered list of strings if successful, otherwise None.

Return type:

List[str] | None

async order_briefed(seq: List[fabricatio_core.models.generic.WithBriefing], requirement: str, **kwargs: Unpack[fabricatio_capabilities.models.kwargs_types.OrderStringKwargs]) List[fabricatio_core.models.generic.WithBriefing] | None

Orders a list of WithBriefing objects based on a given requirement using their names for language model processing.

This method extracts the ‘name’ attributes from the WithBriefing objects to form a sequence of strings, then utilizes the order_string method to obtain an ordered list of names. Finally, it reconstructs the ordered list using the original WithBriefing objects.

Parameters:
  • seq (List[WithBriefing]) – The input sequence of WithBriefing objects to be ordered.

  • requirement (str) – The requirement string guiding the ordering.

  • **kwargs – Additional keyword arguments unpacked and passed to the order_string method.

Returns:

Ordered list of WithBriefing objects if successful, otherwise None.

Return type:

List[WithBriefing] | None

async order(seq: List[str], requirement: str, **kwargs: Unpack[fabricatio_capabilities.models.kwargs_types.OrderStringKwargs]) List[str] | None
async order(seq: List[fabricatio_core.models.generic.WithBriefing], requirement: str, **kwargs: Unpack[fabricatio_capabilities.models.kwargs_types.OrderStringKwargs]) List[fabricatio_core.models.generic.WithBriefing] | None

Orders a sequence of either strings or WithBriefing objects based on a requirement.

Parameters:
  • seq (List[str] | List[WithBriefing]) – Input sequence to be ordered.

  • requirement (str) – Requirement guiding the ordering.

  • **kwargs – Keyword arguments for further customization.

Returns:

Ordered sequence or None if invalid input.

Return type:

None | List[str] | List[WithBriefing]

async order_rated(seq: List[str], reverse: bool = False, **kwargs: Unpack[fabricatio_capabilities.models.kwargs_types.CompositeScoreKwargs]) List[str] | None
async order_rated(seq: List[fabricatio_core.models.generic.WithBriefing], reverse: bool = False, **kwargs: Unpack[fabricatio_capabilities.models.kwargs_types.CompositeScoreKwargs]) List[fabricatio_core.models.generic.WithBriefing] | None

Orders a sequence based on composite scores calculated from their briefings or content.

Parameters:
  • seq (List[str] | List[WithBriefing]) – Sequence to rate and order.

  • reverse (bool) – Whether to reverse the sorting order. Defaults to False.

  • **kwargs – Arguments for score calculation.

Returns:

Ordered sequence based on scores.

Return type:

None | List[str] | List[WithBriefing]