Skip to content

modifiers

ApplStr

ApplStr(
    sep: Optional[str] = None,
    indexing: Union[Indexing, Optional[str]] = None,
    indent: Optional[Union[str, int]] = None,
    new_indent: Optional[Union[str, int]] = None,
    is_inline: Optional[bool] = None,
    role: Optional[MessageRole] = None,
    _ctx: Optional[PromptContext] = None,
)

Bases: Compositor

A compositor that represents a string in the prompt.

Attributes:

  • _sep

    The class default separator string is an empty string.

  • _new_indent

    The class default new indentation string is an empty string.

  • _is_inline

    The class default inline flag is True.

Examples:

>>> with ApplStr():
...     "Hello, "
...     "world!"
<<< The prompt will be:
Hello, world!

Parameters:

  • sep (Optional[str], default: None ) –

    The separator string. Defaults to use the class default.

  • indexing (Union[Indexing, Optional[str]], default: None ) –

    The indexing mode. Defaults to use the class default.

  • indent (Optional[Union[str, int]], default: None ) –

    The indentation string. Defaults to use the class default.

  • new_indent (Optional[Union[str, int]], default: None ) –

    The new indentation string. Defaults to use the class default.

  • is_inline (Optional[bool], default: None ) –

    Flag indicating if the modifier is inline. Defaults to use the class default.

  • role (Optional[MessageRole], default: None ) –

    The role of the modifier. Defaults to use the class default.

  • _ctx (Optional[PromptContext], default: None ) –

    The prompt context filled automatically by the APPL function.

Source code in src/appl/core/modifiers.py
def __init__(
    self,
    sep: Optional[str] = None,
    indexing: Union[Indexing, Optional[str]] = None,
    indent: Optional[Union[str, int]] = None,
    new_indent: Optional[Union[str, int]] = None,
    is_inline: Optional[bool] = None,
    role: Optional[MessageRole] = None,
    _ctx: Optional[PromptContext] = None,
):
    """Initialize the Compositor object.

    Args:
        sep:
            The separator string. Defaults to use the class default.
        indexing:
            The indexing mode. Defaults to use the class default.
        indent:
            The indentation string. Defaults to use the class default.
        new_indent:
            The new indentation string. Defaults to use the class default.
        is_inline:
            Flag indicating if the modifier is inline. Defaults to use the class default.
        role:
            The role of the modifier. Defaults to use the class default.
        _ctx: The prompt context filled automatically by the APPL function.
    """
    super().__init__(_ctx)
    if sep is not None:
        self._sep = sep
    if indexing is not None:
        if isinstance(indexing, str):
            indexing = Indexing(indexing)
        self._indexing = indexing
    else:
        if self._indexing is None:
            raise ValueError("Indexing must be provided.")
        self._indexing = copy.copy(self._indexing)
        # copy to avoid changing the class default
    if indent is not None:
        if isinstance(indent, int):
            indent = " " * indent
        self._inc_indent = indent
    if new_indent is not None:
        if isinstance(new_indent, int):
            new_indent = " " * new_indent
        self._new_indent = new_indent
    if is_inline is not None:
        self._is_inline = is_inline
    if role is not None:
        self._new_role = role

Compositor

Compositor(
    sep: Optional[str] = None,
    indexing: Union[Indexing, Optional[str]] = None,
    indent: Optional[Union[str, int]] = None,
    new_indent: Optional[Union[str, int]] = None,
    is_inline: Optional[bool] = None,
    role: Optional[MessageRole] = None,
    _ctx: Optional[PromptContext] = None,
)

Bases: PrinterModifier

The contextual compositor of the prompts.

This class represents a contextual compositor that modifies the behavior of the printer. It provides various options for customizing the output format of the prompts within this context manager.

Attributes:

  • _sep (Optional[str]) –

    The class default separator string is None, indicating inherit from the parent.

  • _indexing (Indexing) –

    The class default indexing mode is empty indexing.

  • _inc_indent (str) –

    The class default indentation string is empty string.

  • _new_indent (Optional[str]) –

    The class default new indentation string is None, indicating not overwrite the indent.

  • _is_inline (bool) –

    The class default inline flag is False.

  • _new_role (Optional[MessageRole]) –

    The class default role of the modifier is None, indicating not overwrite the role.

Parameters:

  • sep (Optional[str], default: None ) –

    The separator string. Defaults to use the class default.

  • indexing (Union[Indexing, Optional[str]], default: None ) –

    The indexing mode. Defaults to use the class default.

  • indent (Optional[Union[str, int]], default: None ) –

    The indentation string. Defaults to use the class default.

  • new_indent (Optional[Union[str, int]], default: None ) –

    The new indentation string. Defaults to use the class default.

  • is_inline (Optional[bool], default: None ) –

    Flag indicating if the modifier is inline. Defaults to use the class default.

  • role (Optional[MessageRole], default: None ) –

    The role of the modifier. Defaults to use the class default.

  • _ctx (Optional[PromptContext], default: None ) –

    The prompt context filled automatically by the APPL function.

Source code in src/appl/core/modifiers.py
def __init__(
    self,
    sep: Optional[str] = None,
    indexing: Union[Indexing, Optional[str]] = None,
    indent: Optional[Union[str, int]] = None,
    new_indent: Optional[Union[str, int]] = None,
    is_inline: Optional[bool] = None,
    role: Optional[MessageRole] = None,
    _ctx: Optional[PromptContext] = None,
):
    """Initialize the Compositor object.

    Args:
        sep:
            The separator string. Defaults to use the class default.
        indexing:
            The indexing mode. Defaults to use the class default.
        indent:
            The indentation string. Defaults to use the class default.
        new_indent:
            The new indentation string. Defaults to use the class default.
        is_inline:
            Flag indicating if the modifier is inline. Defaults to use the class default.
        role:
            The role of the modifier. Defaults to use the class default.
        _ctx: The prompt context filled automatically by the APPL function.
    """
    super().__init__(_ctx)
    if sep is not None:
        self._sep = sep
    if indexing is not None:
        if isinstance(indexing, str):
            indexing = Indexing(indexing)
        self._indexing = indexing
    else:
        if self._indexing is None:
            raise ValueError("Indexing must be provided.")
        self._indexing = copy.copy(self._indexing)
        # copy to avoid changing the class default
    if indent is not None:
        if isinstance(indent, int):
            indent = " " * indent
        self._inc_indent = indent
    if new_indent is not None:
        if isinstance(new_indent, int):
            new_indent = " " * new_indent
        self._new_indent = new_indent
    if is_inline is not None:
        self._is_inline = is_inline
    if role is not None:
        self._new_role = role

PrinterModifier

PrinterModifier(_ctx: Optional[PromptContext] = None)

Bases: AbstractContextManager

The contextual compositor of the prompt printer.

Controls the behavior of the prompt printer within the context manager. Should only be used within the APPL function.

Parameters:

  • _ctx (Optional[PromptContext], default: None ) –

    The prompt context filled automatically by the APPL function.

Source code in src/appl/core/modifiers.py
def __init__(self, _ctx: Optional[PromptContext] = None):
    """Initialize the PrinterModifier object.

    Args:
        _ctx: The prompt context filled automatically by the APPL function.
    """
    self._ctx = _ctx

push_args property

push_args: PrinterPush

The arguments to push to the printer.