Templates

Functions for generating context template or converting inputs ito some specific format


lotd.generate_chat_template

generate_chat_template(last_only: bool = False, wrapper: str = '{{template}}', system_tags: Tuple[str, str] = ('<|system|>', '<|end|>'), user_tags: Tuple[str, str] = ('<|user|>', '<|end|>'), assistant_tags: Tuple[str, str] = ('<|assistant|>', '<|end|>')) -> str

Generate chat template for instruction tuning.

Parameters:
  • last_only (bool, default: False ) –

    only enable generation for last response. If true, assistant_masks ignores previous responses. Default: False.

  • wrapper (str, default: '{{template}}' ) –

    a wrapper for adding text before and after the template. Should contain {{template}}.

  • system_tags (Tuple[str, str], default: ('<|system|>', '<|end|>') ) –

    a pair of tags to mark the beginning and the end of a system role in a dialog.

  • user_tags (Tuple[str, str], default: ('<|user|>', '<|end|>') ) –

    see system_tags.

  • assistant_tags (Tuple[str, str], default: ('<|assistant|>', '<|end|>') ) –

    see system_tags.

Returns:
  • str

    a jinja2 template string.


lotd.format_chat

format_chat(prompts: Union[str, List[str]] = [], responses: Union[str, List[str]] = [], system: Union[str, None] = None) -> List[Dict[str, str]]

Format list of prompts, responses and system messages into a chat.

Parameters:
  • prompts (Union[str, List[str]], default: [] ) –

    a single prompt or a list of prompts provided by a user in a dialog.

  • responses (Union[str, List[str]], default: [] ) –

    a single response or a list of responses producrd by a model in a dialog.

  • system (Union[str, None], default: None ) –

    system prompt used for this chat.

Returns:
  • List[Dict[str, str]]

    a list of messages of form [{"role": "...", "content": "..."}, ...].