Repository: hiyouga/LLaMA-Factory
File: src/llamafactory/data/template.py (Python)

Code before:


_register_template(
    name="intern",
    format_user=StringFormatter(slots=["
:{{content}}\n
:"]),
    format_assistant=StringFormatter(slots=["{{content}}<eoa>\n"]),
    format_system=StringFormatter(slots=["
:{{content}}\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["<eoa>"],
)


_register_template(
    name="intern2",
    format_user=StringFormatter(slots=["
user\n{{content}}
\n
assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}
\n"]),
    format_system=StringFormatter(slots=["
system\n{{content}}
\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["
"],
)

_register_template(
    name="intern3",
    format_user=StringFormatter(slots=["
user\n{{content}}
\n
assistant\n"]),
    format_system=StringFormatter(slots=["
system\n{{content}}
\n"]),
    format_separator=EmptyFormatter(slots=["
\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["
"],
    efficient_eos=True,  # internlm3 tokenizer cannot set eos_token_id
)

_register_template(
    name="llama2",
    format_user=StringFormatter(slots=[{"bos_token"}, "
 {{content}} 
"]),
    format_system=StringFormatter(slots=["
\n{{content}}\n
\n\n"]),
)


# copied from llama2 template
_register_template(
    name="llama2_zh",
    format_user=StringFormatter(slots=[{"bos_token"}, "
 {{content}} 
"]),
    format_system=StringFormatter(slots=["
\n{{content}}\n
\n\n"]),
    default_system="You are a helpful assistant. 你是一个乐于助人的助手。",
)


_register_template(
    name="llama3",
    format_user=StringFormatter(
        slots=[

Review comment (suggestion):
the `format_separator` has been deprecated, use `format_assistant` instead: https://github.com/hiyouga/LLaMA-Factory/blob/98189c8e4d70bf5f8ee83852a023ed27dfc96900/src/llamafactory/data/template.py#L726-L733

Code after:


_register_template(
    name="intern",
    format_user=StringFormatter(slots=["
:{{content}}\n
:"]),
    format_assistant=StringFormatter(slots=["{{content}}<eoa>\n"]),
    format_system=StringFormatter(slots=["
:{{content}}\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["<eoa>"],
)


_register_template(
    name="intern2",
    format_user=StringFormatter(slots=["
user\n{{content}}
\n
assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}
\n"]),
    format_system=StringFormatter(slots=["
system\n{{content}}
\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["
"],
)

_register_template(
    name="intern3",
    format_user=StringFormatter(slots=["
user\n{{content}}
\n
assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}
\n"]),
    format_system=StringFormatter(slots=["
system\n{{content}}
\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["
"]
)

_register_template(
    name="llama2",
    format_user=StringFormatter(slots=[{"bos_token"}, "
 {{content}} 
"]),
    format_system=StringFormatter(slots=["
\n{{content}}\n
\n\n"]),
)


# copied from llama2 template
_register_template(
    name="llama2_zh",
    format_user=StringFormatter(slots=[{"bos_token"}, "
 {{content}} 
"]),
    format_system=StringFormatter(slots=["
\n{{content}}\n
\n\n"]),
    default_system="You are a helpful assistant. 你是一个乐于助人的助手。",
)


_register_template(
    name="llama3",
    format_user=StringFormatter(
        slots=[
            (