Message formatting#

These are building blocks of the message formatting in a dialogue with large language model. The basic types could be included into the project like following:

#include <metalchat/format.h>

using namespace metalchat::text;

Basic message formatting#

template<typename CharT>
class basic_message#
template<typename Index, typename CharT>
struct basic_formatter#

Public Functions

virtual ~basic_formatter() = default#

The basic_formatter virtual destructor.

Token scanning#

template<typename Index>
class basic_token_scanner#

Subclassed by metalchat::composite_token_scanner< Index, LogicalOp >, metalchat::limit_token_scanner< Index >, metalchat::match_token_scanner< Index >

Public Functions

inline virtual void reset()#

Rests the state of a scanner.

The default implementation does nothing.

virtual ~basic_token_scanner() = default#

The basic_token_scanner default destructor.

template<typename Index>
class match_token_scanner : public metalchat::basic_token_scanner<Index>#

Public Functions

inline virtual void reset() override#

Does nothing, match_token_scanner is stateless.

template<typename Index>
class limit_token_scanner : public metalchat::basic_token_scanner<Index>#

Public Functions

inline virtual void reset() override#

Resets the number of tokens scanned since the last reset.

template<typename Index, typename LogicalOp>
class composite_token_scanner : public metalchat::basic_token_scanner<Index>#

Public Functions

inline composite_token_scanner()#

The default composite_token_scanner constructor.

inline virtual void reset() override#

Resets the states of all underlying token scallers.

Meta Llama 3 formatting#

The implementation of the Meta Llama 3 formatting is implemented in the huggingface library, and could be imported like in the example below:

#include <metalchat/huggingface/llama.h>

using namespace metalchat::huggingface;
template<typename Tokenizer>
class llama3_formatter : public metalchat::basic_formatter<int32_t, char>#

See also

More details on prompt engineering, refer to the Llama 3.1 Prompt Template Guide.

Google Gemma 3 formatting#

The implementation of the Google Gemma 3formatting is implemented in the huggingface library, and could be imported like in the example below:

#include <metalchat/huggingface/gemma.h>

using namespace metalchat::huggingface;
template<typename Tokenizer>
class gemma3_formatter : public metalchat::basic_formatter<int32_t, char>#

See also

More details on prompt engineering, refer to the Gemma formatting and system instructions.