def get_text(
    example: dict[str, str],
    chat_template: Union[bool, str] = None,
    message_col: str = "messages",
    formatting_func: Callable = None,
    template: str = None,
    cols: list[str] = None,
    add_special_tokens: bool = False,
    tokenizer: transformers.PreTrainedTokenizer = None,
):
    """Get text from example using formatting_func, template, or cols."""
    if chat_template:
        # do we need to add generation prompt?
        return tokenizer.apply_chat_template(
            example[message_col],
            tokenize=False,
            chat_template=chat_template if isinstance(chat_template, str) else None,
        )

    if formatting_func:
        text = formatting_func(example)
    elif template:
        text = template.format(**example)
    elif cols:
        text = " ".join([example[col] for col in cols])
    else:
        raise ValueError("None of formatting_func, template, or cols is specified")
    if add_special_tokens:
        # add bos and eos tokens
        text = f"{tokenizer.bos_token} {text} {tokenizer.eos_token}"
    return text
Get text from example using formatting_func, template, or cols.
olive/data/component/text_generation.py