template.py 50.4 KB
Newer Older
chenych's avatar
chenych committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2024 the LlamaFactory team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
15
16
17
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple, Union

luopl's avatar
luopl committed
18
19
from typing_extensions import override

luopl's avatar
luopl committed
20
from ..extras import logging
luopl's avatar
luopl committed
21
from ..extras.misc import check_version
chenych's avatar
chenych committed
22
from .data_utils import Role
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
23
from .formatter import EmptyFormatter, FunctionFormatter, StringFormatter, ToolFormatter
luopl's avatar
luopl committed
24
from .mm_plugin import get_mm_plugin
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
25
26
27
28
29


if TYPE_CHECKING:
    from transformers import PreTrainedTokenizer

luopl's avatar
luopl committed
30
    from ..hparams import DataArguments
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
31
    from .formatter import SLOTS, Formatter
luopl's avatar
luopl committed
32
    from .mm_plugin import BasePlugin
luopl's avatar
luopl committed
33
    from .tool_utils import FunctionCall
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
34
35


luopl's avatar
luopl committed
36
logger = logging.get_logger(__name__)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
37
38
39
40
41
42
43
44
45
46


@dataclass
class Template:
    format_user: "Formatter"
    format_assistant: "Formatter"
    format_system: "Formatter"
    format_function: "Formatter"
    format_observation: "Formatter"
    format_tools: "Formatter"
chenych's avatar
chenych committed
47
    format_prefix: "Formatter"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
48
49
50
51
    default_system: str
    stop_words: List[str]
    efficient_eos: bool
    replace_eos: bool
luopl's avatar
luopl committed
52
53
    replace_jinja_template: bool
    mm_plugin: "BasePlugin"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
54
55
56
57

    def encode_oneturn(
        self,
        tokenizer: "PreTrainedTokenizer",
chenych's avatar
chenych committed
58
        messages: Sequence[Dict[str, str]],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
59
60
61
62
63
64
        system: Optional[str] = None,
        tools: Optional[str] = None,
    ) -> Tuple[List[int], List[int]]:
        r"""
        Returns a single pair of token ids representing prompt and response respectively.
        """
chenych's avatar
chenych committed
65
        encoded_messages = self._encode(tokenizer, messages, system, tools)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
66
        prompt_ids = []
chenych's avatar
chenych committed
67
68
69
70
        for encoded_ids in encoded_messages[:-1]:
            prompt_ids += encoded_ids

        answer_ids = encoded_messages[-1]
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
71
72
73
74
75
        return prompt_ids, answer_ids

    def encode_multiturn(
        self,
        tokenizer: "PreTrainedTokenizer",
chenych's avatar
chenych committed
76
        messages: Sequence[Dict[str, str]],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
77
78
        system: Optional[str] = None,
        tools: Optional[str] = None,
chenych's avatar
chenych committed
79
    ) -> List[Tuple[List[int], List[int]]]:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
80
81
82
        r"""
        Returns multiple pairs of token ids representing prompts and responses respectively.
        """
chenych's avatar
chenych committed
83
84
85
        encoded_messages = self._encode(tokenizer, messages, system, tools)
        return [(encoded_messages[i], encoded_messages[i + 1]) for i in range(0, len(encoded_messages), 2)]

luopl's avatar
luopl committed
86
    def extract_tool(self, content: str) -> Union[str, List["FunctionCall"]]:
chenych's avatar
chenych committed
87
88
89
90
        r"""
        Extracts tool message.
        """
        return self.format_tools.extract(content)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
91

luopl's avatar
luopl committed
92
93
94
95
96
97
98
99
100
101
    def get_stop_token_ids(self, tokenizer: "PreTrainedTokenizer") -> List[int]:
        r"""
        Returns stop token ids.
        """
        stop_token_ids = {tokenizer.eos_token_id}
        for token in self.stop_words:
            stop_token_ids.add(tokenizer.convert_tokens_to_ids(token))

        return list(stop_token_ids)

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
102
103
104
    def _encode(
        self,
        tokenizer: "PreTrainedTokenizer",
chenych's avatar
chenych committed
105
106
107
108
        messages: Sequence[Dict[str, str]],
        system: Optional[str],
        tools: Optional[str],
    ) -> List[List[int]]:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
109
110
        r"""
        Encodes formatted inputs to pairs of token ids.
chenych's avatar
chenych committed
111
112
        Turn 0: prefix + system + query        resp
        Turn t: sep + query                    resp
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
113
114
115
116
117
        """
        system = system or self.default_system
        encoded_messages = []
        for i, message in enumerate(messages):
            elements = []
chenych's avatar
chenych committed
118
119
120
121
122
123
124

            if i == 0:
                elements += self.format_prefix.apply()
                if system or tools:
                    tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
                    elements += self.format_system.apply(content=(system + tool_text))

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
125
126
127
128
129
130
131
132
133
134
135
136
137
            if message["role"] == Role.USER.value:
                elements += self.format_user.apply(content=message["content"], idx=str(i // 2))
            elif message["role"] == Role.ASSISTANT.value:
                elements += self.format_assistant.apply(content=message["content"])
            elif message["role"] == Role.OBSERVATION.value:
                elements += self.format_observation.apply(content=message["content"])
            elif message["role"] == Role.FUNCTION.value:
                elements += self.format_function.apply(content=message["content"])
            else:
                raise NotImplementedError("Unexpected role: {}".format(message["role"]))

            encoded_messages.append(self._convert_elements_to_ids(tokenizer, elements))

chenych's avatar
chenych committed
138
        return encoded_messages
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
139

chenych's avatar
chenych committed
140
    def _convert_elements_to_ids(self, tokenizer: "PreTrainedTokenizer", elements: "SLOTS") -> List[int]:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
        r"""
        Converts elements to token ids.
        """
        token_ids = []
        for elem in elements:
            if isinstance(elem, str):
                if len(elem) != 0:
                    token_ids += tokenizer.encode(elem, add_special_tokens=False)
            elif isinstance(elem, dict):
                token_ids += [tokenizer.convert_tokens_to_ids(elem.get("token"))]
            elif isinstance(elem, set):
                if "bos_token" in elem and tokenizer.bos_token_id is not None:
                    token_ids += [tokenizer.bos_token_id]
                elif "eos_token" in elem and tokenizer.eos_token_id is not None:
                    token_ids += [tokenizer.eos_token_id]
            else:
luopl's avatar
luopl committed
157
                raise ValueError(f"Input must be string, set[str] or dict[str, str], got {type(elem)}")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
158
159
160
161
162
163

        return token_ids


@dataclass
class Llama2Template(Template):
luopl's avatar
luopl committed
164
    @override
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
165
166
167
    def _encode(
        self,
        tokenizer: "PreTrainedTokenizer",
chenych's avatar
chenych committed
168
        messages: Sequence[Dict[str, str]],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
169
170
        system: str,
        tools: str,
chenych's avatar
chenych committed
171
    ) -> List[List[int]]:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
172
173
        r"""
        Encodes formatted inputs to pairs of token ids.
chenych's avatar
chenych committed
174
175
        Turn 0: prefix + system + query        resp
        Turn t: sep + query                    resp
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
176
177
178
179
180
        """
        system = system or self.default_system
        encoded_messages = []
        for i, message in enumerate(messages):
            elements = []
chenych's avatar
chenych committed
181

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
182
            system_text = ""
chenych's avatar
chenych committed
183
184
185
186
187
188
            if i == 0:
                elements += self.format_prefix.apply()
                if system or tools:
                    tool_text = self.format_tools.apply(content=tools)[0] if tools else ""
                    system_text = self.format_system.apply(content=(system + tool_text))[0]

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
189
190
191
192
193
194
195
196
197
198
199
200
201
            if message["role"] == Role.USER.value:
                elements += self.format_user.apply(content=system_text + message["content"])
            elif message["role"] == Role.ASSISTANT.value:
                elements += self.format_assistant.apply(content=message["content"])
            elif message["role"] == Role.OBSERVATION.value:
                elements += self.format_observation.apply(content=message["content"])
            elif message["role"] == Role.FUNCTION.value:
                elements += self.format_function.apply(content=message["content"])
            else:
                raise NotImplementedError("Unexpected role: {}".format(message["role"]))

            encoded_messages.append(self._convert_elements_to_ids(tokenizer, elements))

chenych's avatar
chenych committed
202
        return encoded_messages
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
203
204


luopl's avatar
luopl committed
205
TEMPLATES: Dict[str, "Template"] = {}
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
206
207
208
209
210
211
212
213
214
215


def _register_template(
    name: str,
    format_user: Optional["Formatter"] = None,
    format_assistant: Optional["Formatter"] = None,
    format_system: Optional["Formatter"] = None,
    format_function: Optional["Formatter"] = None,
    format_observation: Optional["Formatter"] = None,
    format_tools: Optional["Formatter"] = None,
chenych's avatar
chenych committed
216
    format_prefix: Optional["Formatter"] = None,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
217
    default_system: str = "",
luopl's avatar
luopl committed
218
    stop_words: Optional[Sequence[str]] = None,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
219
220
    efficient_eos: bool = False,
    replace_eos: bool = False,
luopl's avatar
luopl committed
221
    replace_jinja_template: bool = False,
luopl's avatar
luopl committed
222
    mm_plugin: "BasePlugin" = get_mm_plugin(name="base"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
223
224
225
226
227
228
) -> None:
    r"""
    Registers a chat template.

    To add the following chat template:
    ```
luopl's avatar
luopl committed
229
230
231
232
    <s><user>user prompt here
    <model>model response here</s>
    <user>user prompt here
    <model>model response here</s>
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
233
234
235
236
237
238
    ```

    The corresponding code should be:
    ```
    _register_template(
        name="custom",
luopl's avatar
luopl committed
239
240
241
        format_user=StringFormatter(slots=["<user>{{content}}\n<model>"]),
        format_assistant=StringFormatter(slots=["{{content}}</s>\n"]),
        format_prefix=EmptyFormatter("<s>"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
242
243
244
    )
    ```
    """
luopl's avatar
luopl committed
245
246
    template_class = Llama2Template if any(k in name for k in ("llama2", "mistral", "pixtral")) else Template
    default_slots = ["{{content}}"] if efficient_eos else ["{{content}}", {"eos_token"}]
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
247
    default_user_formatter = StringFormatter(slots=["{{content}}"])
luopl's avatar
luopl committed
248
249
    default_assistant_formatter = StringFormatter(slots=default_slots)
    default_function_formatter = FunctionFormatter(slots=default_slots, tool_format="default")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
250
    default_tool_formatter = ToolFormatter(tool_format="default")
chenych's avatar
chenych committed
251
252
    default_prefix_formatter = EmptyFormatter()
    TEMPLATES[name] = template_class(
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
253
254
255
256
257
258
        format_user=format_user or default_user_formatter,
        format_assistant=format_assistant or default_assistant_formatter,
        format_system=format_system or default_user_formatter,
        format_function=format_function or default_function_formatter,
        format_observation=format_observation or format_user or default_user_formatter,
        format_tools=format_tools or default_tool_formatter,
chenych's avatar
chenych committed
259
        format_prefix=format_prefix or default_prefix_formatter,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
260
        default_system=default_system,
luopl's avatar
luopl committed
261
        stop_words=stop_words or [],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
262
263
        efficient_eos=efficient_eos,
        replace_eos=replace_eos,
luopl's avatar
luopl committed
264
265
        replace_jinja_template=replace_jinja_template,
        mm_plugin=mm_plugin,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
266
267
268
269
270
271
272
273
    )


def _add_or_replace_eos_token(tokenizer: "PreTrainedTokenizer", eos_token: str) -> None:
    is_added = tokenizer.eos_token_id is None
    num_added_tokens = tokenizer.add_special_tokens({"eos_token": eos_token})

    if is_added:
luopl's avatar
luopl committed
274
        logger.info_rank0(f"Add eos token: {tokenizer.eos_token}")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
275
    else:
luopl's avatar
luopl committed
276
        logger.info_rank0(f"Replace eos token: {tokenizer.eos_token}")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
277
278

    if num_added_tokens > 0:
luopl's avatar
luopl committed
279
        logger.warning_rank0("New tokens have been added, make sure `resize_vocab` is True.")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
280
281
282


def _jinja_escape(content: str) -> str:
chenych's avatar
chenych committed
283
    return content.replace("'", r"\'")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
284
285
286
287
288
289
290
291
292
293
294
295
296


def _convert_slots_to_jinja(slots: "SLOTS", tokenizer: "PreTrainedTokenizer", placeholder: str = "content") -> str:
    slot_items = []
    for slot in slots:
        if isinstance(slot, str):
            slot_pieces = slot.split("{{content}}")
            if slot_pieces[0]:
                slot_items.append("'" + _jinja_escape(slot_pieces[0]) + "'")
            if len(slot_pieces) > 1:
                slot_items.append(placeholder)
                if slot_pieces[1]:
                    slot_items.append("'" + _jinja_escape(slot_pieces[1]) + "'")
chenych's avatar
chenych committed
297
298
        elif isinstance(slot, set):  # do not use {{ eos_token }} since it may be replaced
            if "bos_token" in slot and tokenizer.bos_token_id is not None:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
299
                slot_items.append("'" + tokenizer.bos_token + "'")
chenych's avatar
chenych committed
300
            elif "eos_token" in slot and tokenizer.eos_token_id is not None:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
301
302
303
304
305
306
307
308
                slot_items.append("'" + tokenizer.eos_token + "'")
        elif isinstance(slot, dict):
            raise ValueError("Dict is not supported.")

    return " + ".join(slot_items)


def _get_jinja_template(template: "Template", tokenizer: "PreTrainedTokenizer") -> str:
luopl's avatar
luopl committed
309
310
311
    r"""
    Returns the jinja template.
    """
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
312
313
    jinja_template = ""

chenych's avatar
chenych committed
314
315
316
317
    prefix = _convert_slots_to_jinja(template.format_prefix.apply(), tokenizer)
    if prefix:
        jinja_template += "{{ " + prefix + " }}"

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
318
319
320
321
    if template.default_system:
        jinja_template += "{% set system_message = '" + _jinja_escape(template.default_system) + "' %}"

    jinja_template += (
chenych's avatar
chenych committed
322
323
        "{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}"
        "{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% endif %}"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
324
325
326
    )

    system_message = _convert_slots_to_jinja(template.format_system.apply(), tokenizer, placeholder="system_message")
chenych's avatar
chenych committed
327
    if not isinstance(template, Llama2Template):
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
328
329
        jinja_template += "{% if system_message is defined %}{{ " + system_message + " }}{% endif %}"

chenych's avatar
chenych committed
330
    jinja_template += "{% for message in loop_messages %}"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
331
332
333
334
335
    jinja_template += "{% set content = message['content'] %}"
    if isinstance(template, Llama2Template):
        jinja_template += "{% if loop.index0 == 0 and system_message is defined %}"
        jinja_template += "{% set content = " + system_message + " + message['content'] %}"
        jinja_template += "{% endif %}"
chenych's avatar
chenych committed
336

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
337
338
339
    jinja_template += "{% if message['role'] == 'user' %}"
    user_message = _convert_slots_to_jinja(template.format_user.apply(), tokenizer)
    jinja_template += "{{ " + user_message + " }}"
chenych's avatar
chenych committed
340

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
341
    jinja_template += "{% elif message['role'] == 'assistant' %}"
luopl's avatar
luopl committed
342
    assistant_message = _convert_slots_to_jinja(template.format_assistant.apply(), tokenizer)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
343
344
345
346
347
348
    jinja_template += "{{ " + assistant_message + " }}"
    jinja_template += "{% endif %}"
    jinja_template += "{% endfor %}"
    return jinja_template


luopl's avatar
luopl committed
349
350
351
352
353
def get_template_and_fix_tokenizer(tokenizer: "PreTrainedTokenizer", data_args: "DataArguments") -> "Template":
    r"""
    Gets chat template and fixes the tokenizer.
    """
    if data_args.template is None:
chenych's avatar
chenych committed
354
        template = TEMPLATES["empty"]  # placeholder
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
355
    else:
luopl's avatar
luopl committed
356
        template = TEMPLATES.get(data_args.template, None)
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
357
        if template is None:
luopl's avatar
luopl committed
358
359
360
            raise ValueError(f"Template {data_args.template} does not exist.")

    if template.mm_plugin.__class__.__name__ != "BasePlugin":
luopl's avatar
luopl committed
361
        check_version("transformers>=4.45.0")
luopl's avatar
luopl committed
362
363
364

    if data_args.train_on_prompt and template.efficient_eos:
        raise ValueError("Current template does not support `train_on_prompt`.")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
365

luopl's avatar
luopl committed
366
    if data_args.tool_format is not None:
luopl's avatar
luopl committed
367
        logger.info_rank0(f"Using tool format: {data_args.tool_format}.")
luopl's avatar
luopl committed
368
369
        default_slots = ["{{content}}"] if template.efficient_eos else ["{{content}}", {"eos_token"}]
        template.format_function = FunctionFormatter(slots=default_slots, tool_format=data_args.tool_format)
luopl's avatar
luopl committed
370
        template.format_tools = ToolFormatter(tool_format=data_args.tool_format)
chenych's avatar
chenych committed
371

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
372
373
374
375
376
377
378
379
380
381
382
383
384
    stop_words = template.stop_words
    if template.replace_eos:
        if not stop_words:
            raise ValueError("Stop words are required to replace the EOS token.")

        _add_or_replace_eos_token(tokenizer, eos_token=stop_words[0])
        stop_words = stop_words[1:]

    if tokenizer.eos_token_id is None:
        _add_or_replace_eos_token(tokenizer, eos_token="<|endoftext|>")

    if tokenizer.pad_token_id is None:
        tokenizer.pad_token = tokenizer.eos_token
luopl's avatar
luopl committed
385
        logger.info_rank0(f"Add pad token: {tokenizer.pad_token}")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
386
387
388
389
390

    if stop_words:
        num_added_tokens = tokenizer.add_special_tokens(
            dict(additional_special_tokens=stop_words), replace_additional_special_tokens=False
        )
luopl's avatar
luopl committed
391
        logger.info_rank0("Add {} to stop words.".format(",".join(stop_words)))
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
392
        if num_added_tokens > 0:
luopl's avatar
luopl committed
393
            logger.warning_rank0("New tokens have been added, make sure `resize_vocab` is True.")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
394

luopl's avatar
luopl committed
395
    if tokenizer.chat_template is None or template.replace_jinja_template:
luopl's avatar
luopl committed
396
397
        try:
            tokenizer.chat_template = _get_jinja_template(template, tokenizer)
luopl's avatar
luopl committed
398
399
        except ValueError as e:
            logger.info_rank0(f"Cannot add this chat template to tokenizer: {e}.")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
400
401
402
403
404
405
406

    return template


_register_template(
    name="alpaca",
    format_user=StringFormatter(slots=["### Instruction:\n{{content}}\n\n### Response:\n"]),
luopl's avatar
luopl committed
407
    format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
408
    default_system=(
luopl's avatar
luopl committed
409
        "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
410
    ),
luopl's avatar
luopl committed
411
    replace_jinja_template=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
412
413
414
415
416
417
)


_register_template(
    name="aquila",
    format_user=StringFormatter(slots=["Human: {{content}}###Assistant:"]),
luopl's avatar
luopl committed
418
419
    format_assistant=StringFormatter(slots=["{{content}}###"]),
    format_system=StringFormatter(slots=["System: {{content}}###"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
    default_system=(
        "A chat between a curious human and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the human's questions."
    ),
    stop_words=["</s>"],
)


_register_template(
    name="atom",
    format_user=StringFormatter(
        slots=[{"bos_token"}, "Human: {{content}}\n", {"eos_token"}, {"bos_token"}, "Assistant:"]
    ),
    format_assistant=StringFormatter(slots=["{{content}}\n", {"eos_token"}]),
)


_register_template(
    name="baichuan",
    format_user=StringFormatter(slots=[{"token": "<reserved_102>"}, "{{content}}", {"token": "<reserved_103>"}]),
    efficient_eos=True,
)


_register_template(
    name="baichuan2",
    format_user=StringFormatter(slots=["<reserved_106>{{content}}<reserved_107>"]),
    efficient_eos=True,
)


_register_template(
    name="belle",
    format_user=StringFormatter(slots=["Human: {{content}}\n\nBelle: "]),
luopl's avatar
luopl committed
454
    format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n\n"]),
chenych's avatar
chenych committed
455
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
456
457
458
459
460
461
462
463
464
465
466
467
)


_register_template(
    name="bluelm",
    format_user=StringFormatter(slots=[{"token": "[|Human|]:"}, "{{content}}", {"token": "[|AI|]:"}]),
)


_register_template(
    name="breeze",
    format_user=StringFormatter(slots=["[INST] {{content}} [/INST] "]),
chenych's avatar
chenych committed
468
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
469
470
471
472
473
474
475
    efficient_eos=True,
)


_register_template(
    name="chatglm2",
    format_user=StringFormatter(slots=["[Round {{idx}}]\n\n问:{{content}}\n\n答:"]),
chenych's avatar
chenych committed
476
    format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
477
478
479
480
481
482
483
484
    efficient_eos=True,
)


_register_template(
    name="chatglm3",
    format_user=StringFormatter(slots=[{"token": "<|user|>"}, "\n", "{{content}}", {"token": "<|assistant|>"}]),
    format_assistant=StringFormatter(slots=["\n", "{{content}}"]),
chenych's avatar
chenych committed
485
    format_system=StringFormatter(slots=[{"token": "<|system|>"}, "\n", "{{content}}"]),
luopl's avatar
luopl committed
486
    format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
487
488
489
    format_observation=StringFormatter(
        slots=[{"token": "<|observation|>"}, "\n", "{{content}}", {"token": "<|assistant|>"}]
    ),
chenych's avatar
chenych committed
490
491
    format_tools=ToolFormatter(tool_format="glm4"),
    format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
492
493
494
495
496
497
498
499
    stop_words=["<|user|>", "<|observation|>"],
    efficient_eos=True,
)


_register_template(
    name="chatml",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
500
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
501
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
502
    format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
503
504
    stop_words=["<|im_end|>", "<|im_start|>"],
    replace_eos=True,
luopl's avatar
luopl committed
505
    replace_jinja_template=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
506
507
508
)


luopl's avatar
luopl committed
509
# copied from chatml template
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
510
511
512
_register_template(
    name="chatml_de",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
513
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
514
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
515
    format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
516
517
518
    default_system="Du bist ein freundlicher und hilfsbereiter KI-Assistent.",
    stop_words=["<|im_end|>", "<|im_start|>"],
    replace_eos=True,
luopl's avatar
luopl committed
519
    replace_jinja_template=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
520
521
522
523
524
)


_register_template(
    name="codegeex2",
chenych's avatar
chenych committed
525
526
527
528
529
530
531
532
    format_prefix=EmptyFormatter(slots=[{"token": "[gMASK]"}, {"token": "sop"}]),
)


_register_template(
    name="codegeex4",
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>\n"]),
    format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
luopl's avatar
luopl committed
533
    format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
chenych's avatar
chenych committed
534
535
536
537
538
539
540
541
542
    format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>\n"]),
    format_tools=ToolFormatter(tool_format="glm4"),
    format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
    default_system=(
        "你是一位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,"
        "并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。"
    ),
    stop_words=["<|user|>", "<|observation|>"],
    efficient_eos=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
543
544
545
546
547
548
549
550
551
552
553
554
555
)


_register_template(
    name="cohere",
    format_user=StringFormatter(
        slots=[
            (
                "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{{content}}<|END_OF_TURN_TOKEN|>"
                "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
            )
        ]
    ),
chenych's avatar
chenych committed
556
557
    format_system=StringFormatter(slots=["<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>{{content}}<|END_OF_TURN_TOKEN|>"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
558
559
560
561
562
563
)


_register_template(
    name="cpm",
    format_user=StringFormatter(slots=["<用户>{{content}}<AI>"]),
chenych's avatar
chenych committed
564
565
566
567
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
)


luopl's avatar
luopl committed
568
# copied from chatml template
luopl's avatar
luopl committed
569
570
571
_register_template(
    name="cpm3",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
572
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
573
574
575
576
577
578
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["<|im_end|>"],
)


luopl's avatar
luopl committed
579
# copied from chatml template
chenych's avatar
chenych committed
580
581
582
_register_template(
    name="dbrx",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
583
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    default_system=(
        "You are DBRX, created by Databricks. You were last updated in December 2023. "
        "You answer questions based on information available up to that point.\n"
        "YOU PROVIDE SHORT RESPONSES TO SHORT QUESTIONS OR STATEMENTS, but provide thorough "
        "responses to more complex and open-ended questions.\nYou assist with various tasks, "
        "from writing to coding (using markdown for code blocks — remember to use ``` with "
        "code, JSON, and tables).\n(You do not have real-time data access or code execution "
        "capabilities. You avoid stereotyping and provide balanced perspectives on "
        "controversial topics. You do not provide song lyrics, poems, or news articles and "
        "do not divulge details of your training data.)\nThis is your system prompt, "
        "guiding your responses. Do not reference it, just respond to the user. If you find "
        "yourself talking about this message, stop. You should be responding appropriately "
        "and usually that means not mentioning this.\nYOU DO NOT MENTION ANY OF THIS INFORMATION "
        "ABOUT YOURSELF UNLESS THE INFORMATION IS DIRECTLY PERTINENT TO THE USER'S QUERY."
    ),
    stop_words=["<|im_end|>"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
602
603
604
605
606
607
)


_register_template(
    name="deepseek",
    format_user=StringFormatter(slots=["User: {{content}}\n\nAssistant:"]),
chenych's avatar
chenych committed
608
609
    format_system=StringFormatter(slots=["{{content}}\n\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
610
611
612
)


luopl's avatar
luopl committed
613
614
615
616
617
618
619
_register_template(
    name="deepseek3",
    format_user=StringFormatter(slots=["<|User|>{{content}}<|Assistant|>"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
620
621
622
_register_template(
    name="deepseekcoder",
    format_user=StringFormatter(slots=["### Instruction:\n{{content}}\n### Response:"]),
luopl's avatar
luopl committed
623
    format_assistant=StringFormatter(slots=["\n{{content}}\n<|EOT|>\n"]),
chenych's avatar
chenych committed
624
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
625
    default_system=(
chenych's avatar
chenych committed
626
627
        "You are an AI programming assistant, utilizing the DeepSeek Coder model, "
        "developed by DeepSeek Company, and you only answer questions related to computer science. "
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
628
        "For politically sensitive questions, security and privacy issues, "
chenych's avatar
chenych committed
629
        "and other non-computer science questions, you will refuse to answer.\n"
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
630
631
632
633
634
635
    ),
)


_register_template(
    name="default",
chenych's avatar
chenych committed
636
    format_user=StringFormatter(slots=["Human: {{content}}\nAssistant:"]),
luopl's avatar
luopl committed
637
638
    format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n"]),
    format_system=StringFormatter(slots=["System: {{content}}\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
639
640
641
642
643
)


_register_template(
    name="empty",
chenych's avatar
chenych committed
644
    efficient_eos=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
645
646
647
)


luopl's avatar
luopl committed
648
649
650
_register_template(
    name="exaone",
    format_user=StringFormatter(slots=["[|user|]{{content}}\n[|assistant|]"]),
luopl's avatar
luopl committed
651
    format_assistant=StringFormatter(slots=["{{content}}", {"eos_token"}, "\n"]),
luopl's avatar
luopl committed
652
653
654
655
    format_system=StringFormatter(slots=["[|system|]{{content}}[|endofturn|]\n"]),
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
656
657
658
_register_template(
    name="falcon",
    format_user=StringFormatter(slots=["User: {{content}}\nFalcon:"]),
luopl's avatar
luopl committed
659
    format_assistant=StringFormatter(slots=["{{content}}\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
660
661
662
663
664
665
    efficient_eos=True,
)


_register_template(
    name="fewshot",
luopl's avatar
luopl committed
666
    format_assistant=StringFormatter(slots=["{{content}}\n\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
667
668
669
670
671
672
673
    efficient_eos=True,
)


_register_template(
    name="gemma",
    format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
luopl's avatar
luopl committed
674
    format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
chenych's avatar
chenych committed
675
676
677
678
679
680
681
682
683
684
685
686
    format_observation=StringFormatter(
        slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
    ),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
)


_register_template(
    name="glm4",
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>"]),
    format_assistant=StringFormatter(slots=["\n{{content}}"]),
    format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
luopl's avatar
luopl committed
687
    format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4"),
chenych's avatar
chenych committed
688
689
690
691
    format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>"]),
    format_tools=ToolFormatter(tool_format="glm4"),
    format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
    stop_words=["<|user|>", "<|observation|>"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
692
693
694
695
    efficient_eos=True,
)


luopl's avatar
luopl committed
696
697
698
699
700
701
702
703
704
705
706
707
_register_template(
    name="granite3",
    format_user=StringFormatter(
        slots=[
            "<|start_of_role|>user<|end_of_role|>{{content}}<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>"
        ]
    ),
    format_assistant=StringFormatter(slots=["{{content}}<|end_of_text|>\n"]),
    format_system=StringFormatter(slots=["<|start_of_role|>system<|end_of_role|>{{content}}<|end_of_text|>\n"]),
)


luopl's avatar
luopl committed
708
709
710
711
712
713
714
715
_register_template(
    name="index",
    format_user=StringFormatter(slots=["reserved_0{{content}}reserved_1"]),
    format_system=StringFormatter(slots=["<unk>{{content}}"]),
    efficient_eos=True,
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
716
717
_register_template(
    name="intern",
chenych's avatar
chenych committed
718
    format_user=StringFormatter(slots=["<|User|>:{{content}}\n<|Bot|>:"]),
luopl's avatar
luopl committed
719
    format_assistant=StringFormatter(slots=["{{content}}<eoa>\n"]),
chenych's avatar
chenych committed
720
721
    format_system=StringFormatter(slots=["<|System|>:{{content}}\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
722
723
724
725
726
727
728
    stop_words=["<eoa>"],
)


_register_template(
    name="intern2",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
729
730
731
732
733
734
735
736
737
738
739
740
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["<|im_end|>"],
)


# copied from intern2 template
_register_template(
    name="intern3",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
741
742
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
743
744
745
746
747
748
749
750
751
752
753
    stop_words=["<|im_end|>"],
)


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


luopl's avatar
luopl committed
754
# copied from llama2 template
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
_register_template(
    name="llama2_zh",
    format_user=StringFormatter(slots=[{"bos_token"}, "[INST] {{content}} [/INST]"]),
    format_system=StringFormatter(slots=["<<SYS>>\n{{content}}\n<</SYS>>\n\n"]),
    default_system="You are a helpful assistant. 你是一个乐于助人的助手。",
)


_register_template(
    name="llama3",
    format_user=StringFormatter(
        slots=[
            (
                "<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
luopl's avatar
luopl committed
773
    format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
chenych's avatar
chenych committed
774
    format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
luopl's avatar
luopl committed
775
    format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
chenych's avatar
chenych committed
776
777
778
    format_observation=StringFormatter(
        slots=[
            (
luopl's avatar
luopl committed
779
                "<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
chenych's avatar
chenych committed
780
781
782
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
783
    ),
luopl's avatar
luopl committed
784
    format_tools=ToolFormatter(tool_format="llama3"),
chenych's avatar
chenych committed
785
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
luopl's avatar
luopl committed
786
    stop_words=["<|eot_id|>", "<|eom_id|>"],
luopl's avatar
luopl committed
787
788
789
)


luopl's avatar
luopl committed
790
# copied from llama3 template
luopl's avatar
luopl committed
791
792
793
794
795
796
797
798
799
800
_register_template(
    name="mllama",
    format_user=StringFormatter(
        slots=[
            (
                "<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
luopl's avatar
luopl committed
801
    format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
luopl's avatar
luopl committed
802
    format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
luopl's avatar
luopl committed
803
    format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
luopl's avatar
luopl committed
804
805
806
    format_observation=StringFormatter(
        slots=[
            (
luopl's avatar
luopl committed
807
                "<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
luopl's avatar
luopl committed
808
809
810
811
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
luopl's avatar
luopl committed
812
    format_tools=ToolFormatter(tool_format="llama3"),
luopl's avatar
luopl committed
813
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
luopl's avatar
luopl committed
814
    stop_words=["<|eot_id|>", "<|eom_id|>"],
luopl's avatar
luopl committed
815
816
817
818
    mm_plugin=get_mm_plugin(name="mllama", image_token="<|image|>"),
)


luopl's avatar
luopl committed
819
# copied from vicuna template
luopl's avatar
luopl committed
820
821
822
823
824
825
826
827
828
829
830
_register_template(
    name="llava",
    format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
    default_system=(
        "A chat between a curious user and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the user's questions."
    ),
    mm_plugin=get_mm_plugin(name="llava", image_token="<image>"),
)


luopl's avatar
luopl committed
831
# copied from vicuna template
luopl's avatar
luopl committed
832
833
834
835
836
837
838
839
840
841
842
_register_template(
    name="llava_next",
    format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
    default_system=(
        "A chat between a curious user and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the user's questions."
    ),
    mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
)


luopl's avatar
luopl committed
843
# copied from llama3 template
luopl's avatar
luopl committed
844
845
846
847
848
849
850
851
852
853
_register_template(
    name="llava_next_llama3",
    format_user=StringFormatter(
        slots=[
            (
                "<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
luopl's avatar
luopl committed
854
    format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
luopl's avatar
luopl committed
855
    format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
luopl's avatar
luopl committed
856
    format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
luopl's avatar
luopl committed
857
858
859
    format_observation=StringFormatter(
        slots=[
            (
luopl's avatar
luopl committed
860
                "<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
luopl's avatar
luopl committed
861
862
863
864
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
luopl's avatar
luopl committed
865
    format_tools=ToolFormatter(tool_format="llama3"),
luopl's avatar
luopl committed
866
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
luopl's avatar
luopl committed
867
    stop_words=["<|eot_id|>", "<|eom_id|>"],
luopl's avatar
luopl committed
868
869
870
871
    mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
)


luopl's avatar
luopl committed
872
# copied from mistral template
luopl's avatar
luopl committed
873
874
_register_template(
    name="llava_next_mistral",
luopl's avatar
luopl committed
875
876
877
878
879
880
    format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
    format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
    format_system=StringFormatter(slots=["{{content}}\n\n"]),
    format_function=FunctionFormatter(slots=["[TOOL_CALLS] ", "{{content}}", {"eos_token"}], tool_format="mistral"),
    format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
    format_tools=ToolFormatter(tool_format="mistral"),
luopl's avatar
luopl committed
881
882
883
884
885
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
)


luopl's avatar
luopl committed
886
# copied from chatml template
luopl's avatar
luopl committed
887
888
889
_register_template(
    name="llava_next_qwen",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
890
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
891
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
892
893
894
895
896
    format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
    format_observation=StringFormatter(
        slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
    ),
    format_tools=ToolFormatter(tool_format="qwen"),
luopl's avatar
luopl committed
897
898
899
900
901
902
    default_system="You are a helpful assistant.",
    stop_words=["<|im_end|>"],
    mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
)


luopl's avatar
luopl committed
903
# copied from chatml template
luopl's avatar
luopl committed
904
905
906
_register_template(
    name="llava_next_yi",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
907
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
908
909
910
911
912
913
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    stop_words=["<|im_end|>"],
    mm_plugin=get_mm_plugin(name="llava_next", image_token="<image>"),
)


luopl's avatar
luopl committed
914
# copied from vicuna template
luopl's avatar
luopl committed
915
916
917
918
919
920
921
922
923
924
925
_register_template(
    name="llava_next_video",
    format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
    default_system=(
        "A chat between a curious user and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the user's questions."
    ),
    mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
)


luopl's avatar
luopl committed
926
# copied from mistral template
luopl's avatar
luopl committed
927
928
_register_template(
    name="llava_next_video_mistral",
luopl's avatar
luopl committed
929
930
931
932
933
934
    format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
    format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
    format_system=StringFormatter(slots=["{{content}}\n\n"]),
    format_function=FunctionFormatter(slots=["[TOOL_CALLS] ", "{{content}}", {"eos_token"}], tool_format="mistral"),
    format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
    format_tools=ToolFormatter(tool_format="mistral"),
luopl's avatar
luopl committed
935
936
937
938
939
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
)


luopl's avatar
luopl committed
940
# copied from chatml template
luopl's avatar
luopl committed
941
942
943
_register_template(
    name="llava_next_video_yi",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
944
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
945
946
947
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    stop_words=["<|im_end|>"],
    mm_plugin=get_mm_plugin(name="llava_next_video", image_token="<image>", video_token="<video>"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
948
949
950
)


luopl's avatar
luopl committed
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# copied from chatml template
_register_template(
    name="marco",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    default_system=(
        "你是一个经过良好训练的AI助手,你的名字是Marco-o1.由阿里国际数字商业集团的AI Business创造.\n## 重要!!!!!\n"
        "当你回答问题时,你的思考应该在<Thought>内完成,<Output>内输出你的结果。\n"
        "<Thought>应该尽可能是英文,但是有2个特例,一个是对原文中的引用,另一个是是数学应该使用markdown格式,<Output>内的输出需要遵循用户输入的语言。\n"
    ),
    stop_words=["<|im_end|>"],
)


# copied from chatml template
_register_template(
    name="minicpm_v",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    stop_words=["<|im_end|>"],
    mm_plugin=get_mm_plugin(name="minicpm_v", image_token="<image>", video_token="<video>"),
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
978
979
_register_template(
    name="mistral",
luopl's avatar
luopl committed
980
981
982
983
984
985
    format_user=StringFormatter(slots=["[INST] {{content}}[/INST]"]),
    format_assistant=StringFormatter(slots=[" {{content}}", {"eos_token"}]),
    format_system=StringFormatter(slots=["{{content}}\n\n"]),
    format_function=FunctionFormatter(slots=["[TOOL_CALLS] ", "{{content}}", {"eos_token"}], tool_format="mistral"),
    format_observation=StringFormatter(slots=["""[TOOL_RESULTS] {"content": {{content}}}[/TOOL_RESULTS]"""]),
    format_tools=ToolFormatter(tool_format="mistral"),
chenych's avatar
chenych committed
986
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
987
988
989
990
991
)


_register_template(
    name="olmo",
chenych's avatar
chenych committed
992
993
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>\n"]),
    format_prefix=EmptyFormatter(slots=[{"eos_token"}]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
994
995
996
997
998
999
)


_register_template(
    name="openchat",
    format_user=StringFormatter(slots=["GPT4 Correct User: {{content}}", {"eos_token"}, "GPT4 Correct Assistant:"]),
chenych's avatar
chenych committed
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
)


_register_template(
    name="openchat-3.6",
    format_user=StringFormatter(
        slots=[
            (
                "<|start_header_id|>GPT4 Correct User<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>GPT4 Correct Assistant<|end_header_id|>\n\n"
            )
        ]
    ),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    stop_words=["<|eot_id|>"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1016
1017
1018
)


luopl's avatar
luopl committed
1019
# copied from chatml template
luopl's avatar
luopl committed
1020
1021
1022
_register_template(
    name="opencoder",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
1023
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
1024
1025
1026
1027
1028
1029
1030
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    format_observation=StringFormatter(slots=["<|im_start|>tool\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
    default_system="You are OpenCoder, created by OpenCoder Team.",
    stop_words=["<|im_end|>"],
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1031
1032
1033
_register_template(
    name="orion",
    format_user=StringFormatter(slots=["Human: {{content}}\n\nAssistant: ", {"eos_token"}]),
chenych's avatar
chenych committed
1034
1035
1036
1037
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
)


luopl's avatar
luopl committed
1038
# copied from gemma template
luopl's avatar
luopl committed
1039
1040
1041
_register_template(
    name="paligemma",
    format_user=StringFormatter(slots=["<start_of_turn>user\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]),
luopl's avatar
luopl committed
1042
    format_assistant=StringFormatter(slots=["{{content}}<end_of_turn>\n"]),
luopl's avatar
luopl committed
1043
1044
1045
1046
1047
1048
1049
1050
    format_observation=StringFormatter(
        slots=["<start_of_turn>tool\n{{content}}<end_of_turn>\n<start_of_turn>model\n"]
    ),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    mm_plugin=get_mm_plugin(name="paligemma", image_token="<image>"),
)


chenych's avatar
chenych committed
1051
1052
1053
_register_template(
    name="phi",
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>\n"]),
luopl's avatar
luopl committed
1054
    format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
chenych's avatar
chenych committed
1055
1056
    format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
    stop_words=["<|end|>"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1057
1058
1059
)


luopl's avatar
luopl committed
1060
1061
1062
_register_template(
    name="phi_small",
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>\n"]),
luopl's avatar
luopl committed
1063
    format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
luopl's avatar
luopl committed
1064
1065
1066
    format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
    format_prefix=EmptyFormatter(slots=[{"<|endoftext|>"}]),
    stop_words=["<|end|>"],
luopl's avatar
luopl committed
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
)


_register_template(
    name="phi4",
    format_user=StringFormatter(
        slots=["<|im_start|>user<|im_sep|>{{content}}<|im_end|><|im_start|>assistant<|im_sep|>"]
    ),
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>"]),
    format_system=StringFormatter(slots=["<|im_start|>system<|im_sep|>{{content}}<|im_end|>"]),
    stop_words=["<|im_end|>"],
luopl's avatar
luopl committed
1078
1079
1080
1081
1082
)


_register_template(
    name="pixtral",
luopl's avatar
luopl committed
1083
1084
    format_user=StringFormatter(slots=["[INST]{{content}}[/INST]"]),
    format_system=StringFormatter(slots=["{{content}}\n\n"]),
luopl's avatar
luopl committed
1085
1086
1087
1088
1089
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    mm_plugin=get_mm_plugin(name="pixtral", image_token="[IMG]"),
)


luopl's avatar
luopl committed
1090
# copied from chatml template
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1091
1092
1093
_register_template(
    name="qwen",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
1094
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1095
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
1096
1097
1098
1099
1100
    format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
    format_observation=StringFormatter(
        slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
    ),
    format_tools=ToolFormatter(tool_format="qwen"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1101
1102
    default_system="You are a helpful assistant.",
    stop_words=["<|im_end|>"],
luopl's avatar
luopl committed
1103
1104
1105
)


luopl's avatar
luopl committed
1106
# copied from chatml template
luopl's avatar
luopl committed
1107
1108
1109
_register_template(
    name="qwen2_vl",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
1110
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
1111
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
luopl's avatar
luopl committed
1112
1113
1114
1115
1116
    format_function=FunctionFormatter(slots=["{{content}}<|im_end|>\n"], tool_format="qwen"),
    format_observation=StringFormatter(
        slots=["<|im_start|>user\n<tool_response>\n{{content}}\n</tool_response><|im_end|>\n<|im_start|>assistant\n"]
    ),
    format_tools=ToolFormatter(tool_format="qwen"),
luopl's avatar
luopl committed
1117
1118
1119
    default_system="You are a helpful assistant.",
    stop_words=["<|im_end|>"],
    mm_plugin=get_mm_plugin(name="qwen2_vl", image_token="<|image_pad|>", video_token="<|video_pad|>"),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1120
1121
1122
)


chenych's avatar
chenych committed
1123
1124
1125
_register_template(
    name="sailor",
    format_user=StringFormatter(slots=["<|im_start|>question\n{{content}}<|im_end|>\n<|im_start|>answer\n"]),
luopl's avatar
luopl committed
1126
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
1127
1128
1129
1130
1131
1132
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
    default_system=(
        "You are an AI assistant named Sailor created by Sea AI Lab. "
        "Your answer should be friendly, unbiased, faithful, informative and detailed."
    ),
    stop_words=["<|im_end|>"],
luopl's avatar
luopl committed
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
)


# copied from llama3 template
_register_template(
    name="skywork_o1",
    format_user=StringFormatter(
        slots=[
            (
                "<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
    format_assistant=StringFormatter(slots=["{{content}}<|eot_id|>"]),
    format_system=StringFormatter(slots=["<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>"]),
    format_function=FunctionFormatter(slots=["{{content}}<|eot_id|>"], tool_format="llama3"),
    format_observation=StringFormatter(
        slots=[
            (
                "<|start_header_id|>ipython<|end_header_id|>\n\n{{content}}<|eot_id|>"
                "<|start_header_id|>assistant<|end_header_id|>\n\n"
            )
        ]
    ),
    format_tools=ToolFormatter(tool_format="llama3"),
    format_prefix=EmptyFormatter(slots=[{"bos_token"}]),
    default_system=(
        "You are Skywork-o1, a thinking model developed by Skywork AI, specializing in solving complex problems "
        "involving mathematics, coding, and logical reasoning through deep thought. When faced with a user's request, "
        "you first engage in a lengthy and in-depth thinking process to explore possible solutions to the problem. "
        "After completing your thoughts, you then provide a detailed explanation of the solution process "
        "in your response."
    ),
    stop_words=["<|eot_id|>", "<|eom_id|>"],
chenych's avatar
chenych committed
1168
1169
1170
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
_register_template(
    name="solar",
    format_user=StringFormatter(slots=["### User:\n{{content}}\n\n### Assistant:\n"]),
    format_system=StringFormatter(slots=["### System:\n{{content}}\n\n"]),
    efficient_eos=True,
)


_register_template(
    name="starchat",
    format_user=StringFormatter(slots=["<|user|>\n{{content}}<|end|>\n<|assistant|>"]),
luopl's avatar
luopl committed
1182
    format_assistant=StringFormatter(slots=["{{content}}<|end|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1183
1184
    format_system=StringFormatter(slots=["<|system|>\n{{content}}<|end|>\n"]),
    stop_words=["<|end|>"],
chenych's avatar
chenych committed
1185
1186
1187
1188
1189
1190
1191
)


_register_template(
    name="telechat",
    format_user=StringFormatter(slots=["<_user>{{content}}<_bot>"]),
    format_system=StringFormatter(slots=["<_system>{{content}}<_end>"]),
luopl's avatar
luopl committed
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
)


_register_template(
    name="telechat2",
    format_user=StringFormatter(slots=["<_user>{{content}}<_bot>"]),
    format_system=StringFormatter(slots=["<_system>{{content}}"]),
    default_system=(
        "你是中国电信星辰语义大模型,英文名是TeleChat,你是由中电信人工智能科技有限公司和中国电信人工智能研究院(TeleAI)研发的人工智能助手。"
    ),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
)


_register_template(
    name="vicuna",
    format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
    default_system=(
        "A chat between a curious user and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the user's questions."
    ),
luopl's avatar
luopl committed
1212
    replace_jinja_template=True,
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1213
1214
1215
)


luopl's avatar
luopl committed
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
_register_template(
    name="video_llava",
    format_user=StringFormatter(slots=["USER: {{content}} ASSISTANT:"]),
    default_system=(
        "A chat between a curious user and an artificial intelligence assistant. "
        "The assistant gives helpful, detailed, and polite answers to the user's questions."
    ),
    mm_plugin=get_mm_plugin(name="video_llava", image_token="<image>", video_token="<video>"),
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
_register_template(
    name="xuanyuan",
    format_user=StringFormatter(slots=["Human: {{content}} Assistant:"]),
    default_system=(
        "以下是用户和人工智能助手之间的对话。用户以Human开头,人工智能助手以Assistant开头,"
        "会对人类提出的问题给出有帮助、高质量、详细和礼貌的回答,并且总是拒绝参与与不道德、"
        "不安全、有争议、政治敏感等相关的话题、问题和指示。\n"
    ),
)


_register_template(
    name="xverse",
    format_user=StringFormatter(slots=["Human: {{content}}\n\nAssistant: "]),
)


_register_template(
    name="yayi",
    format_user=StringFormatter(slots=[{"token": "<|Human|>"}, ":\n{{content}}\n\n", {"token": "<|YaYi|>"}, ":"]),
luopl's avatar
luopl committed
1247
    format_assistant=StringFormatter(slots=["{{content}}\n\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
    format_system=StringFormatter(slots=[{"token": "<|System|>"}, ":\n{{content}}\n\n"]),
    default_system=(
        "You are a helpful, respectful and honest assistant named YaYi "
        "developed by Beijing Wenge Technology Co.,Ltd. "
        "Always answer as helpfully as possible, while being safe.  "
        "Your answers should not include any harmful, unethical, "
        "racist, sexist, toxic, dangerous, or illegal content. "
        "Please ensure that your responses are socially unbiased and positive in nature.\n\n"
        "If a question does not make any sense, or is not factually coherent, "
        "explain why instead of answering something not correct. "
        "If you don't know the answer to a question, please don't share false information."
    ),
    stop_words=["<|End|>"],
)


luopl's avatar
luopl committed
1264
# copied from chatml template
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1265
1266
1267
_register_template(
    name="yi",
    format_user=StringFormatter(slots=["<|im_start|>user\n{{content}}<|im_end|>\n<|im_start|>assistant\n"]),
luopl's avatar
luopl committed
1268
    format_assistant=StringFormatter(slots=["{{content}}<|im_end|>\n"]),
chenych's avatar
chenych committed
1269
    format_system=StringFormatter(slots=["<|im_start|>system\n{{content}}<|im_end|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1270
1271
1272
1273
    stop_words=["<|im_end|>"],
)


chenych's avatar
chenych committed
1274
1275
1276
_register_template(
    name="yi_vl",
    format_user=StringFormatter(slots=["### Human: {{content}}\n### Assistant:"]),
luopl's avatar
luopl committed
1277
    format_assistant=StringFormatter(slots=["{{content}}\n"]),
chenych's avatar
chenych committed
1278
1279
1280
1281
1282
1283
1284
1285
1286
    default_system=(
        "This is a chat between an inquisitive human and an AI assistant. "
        "Assume the role of the AI assistant. Read all the images carefully, "
        "and respond to the human's questions with informative, helpful, detailed and polite answers. "
        "这是一个好奇的人类和一个人工智能助手之间的对话。假设你扮演这个AI助手的角色。"
        "仔细阅读所有的图像,并对人类的问题做出信息丰富、有帮助、详细的和礼貌的回答。\n\n"
    ),
    stop_words=["###"],
    efficient_eos=True,
luopl's avatar
luopl committed
1287
    mm_plugin=get_mm_plugin(name="llava", image_token="<image>"),
chenych's avatar
chenych committed
1288
1289
1290
)


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1291
1292
1293
_register_template(
    name="yuan",
    format_user=StringFormatter(slots=["{{content}}", {"token": "<sep>"}]),
luopl's avatar
luopl committed
1294
    format_assistant=StringFormatter(slots=["{{content}}<eod>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1295
1296
1297
1298
1299
1300
    stop_words=["<eod>"],
)


_register_template(
    name="zephyr",
chenych's avatar
chenych committed
1301
    format_user=StringFormatter(slots=["<|user|>\n{{content}}", {"eos_token"}, "<|assistant|>\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1302
    format_system=StringFormatter(slots=["<|system|>\n{{content}}", {"eos_token"}]),
chenych's avatar
chenych committed
1303
    default_system="You are Zephyr, a helpful assistant.",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1304
1305
1306
1307
1308
1309
)


_register_template(
    name="ziya",
    format_user=StringFormatter(slots=["<human>:{{content}}\n<bot>:"]),
luopl's avatar
luopl committed
1310
    format_assistant=StringFormatter(slots=["{{content}}\n"]),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
1311
)