Skip to content

prompt_formatter

langroid/language_models/prompt_formatter/init.py

PromptFormatter(config)

Bases: ABC

Abstract base class for a prompt formatter

Source code in langroid/language_models/prompt_formatter/base.py
def __init__(self, config: PromptFormatterConfig):
    self.config = config

format(messages) abstractmethod

Convert sequence of messages (system, user, assistant, user, assistant...user) to a single prompt formatted according to the specific format type, to be used in a /completions endpoint.

Parameters:

Name Type Description Default
messages List[LLMMessage]

chat history as a sequence of messages

required

Returns:

Type Description
str

formatted version of chat history

Source code in langroid/language_models/prompt_formatter/base.py
@abstractmethod
def format(self, messages: List[LLMMessage]) -> str:
    """
    Convert sequence of messages (system, user, assistant, user, assistant...user)
        to a single prompt formatted according to the specific format type,
        to be used in a /completions endpoint.

    Args:
        messages (List[LLMMessage]): chat history as a sequence of messages

    Returns:
        (str): formatted version of chat history

    """
    pass

Llama2Formatter(config)

Bases: PromptFormatter

Source code in langroid/language_models/prompt_formatter/base.py
def __init__(self, config: PromptFormatterConfig):
    self.config = config