CoolFace
Modelpublic

MathLLMs/MathCoder-VL-2B

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
7likes30downloads
conversation.py1261 linesDownload Raw Back to root
1"""2Conversation prompt templates.3 4We kindly request that you import fastchat instead of copying this file if you wish to use it.5If you have any changes in mind, please contribute back so the community can benefit collectively and continue to maintain these valuable templates.6"""7 8import dataclasses9from enum import IntEnum, auto10from typing import Any, Dict, List, Tuple, Union11 12 13class SeparatorStyle(IntEnum):14    """Separator styles."""15 16    ADD_COLON_SINGLE = auto()17    ADD_COLON_TWO = auto()18    ADD_COLON_SPACE_SINGLE = auto()19    NO_COLON_SINGLE = auto()20    NO_COLON_TWO = auto()21    ADD_NEW_LINE_SINGLE = auto()22    LLAMA2 = auto()23    CHATGLM = auto()24    CHATML = auto()25    CHATINTERN = auto()26    DOLLY = auto()27    RWKV = auto()28    PHOENIX = auto()29    ROBIN = auto()30    FALCON_CHAT = auto()31    CHATGLM3 = auto()32    INTERNVL_ZH = auto()33    MPT = auto()34 35 36@dataclasses.dataclass37class Conversation:38    """A class that manages prompt templates and keeps all conversation history."""39 40    # The name of this template41    name: str42    # The template of the system prompt43    system_template: str = '{system_message}'44    # The system message45    system_message: str = ''46    # The names of two roles47    roles: Tuple[str] = ('USER', 'ASSISTANT')48    # All messages. Each item is (role, message).49    messages: List[List[str]] = ()50    # The number of few shot examples51    offset: int = 052    # The separator style and configurations53    sep_style: SeparatorStyle = SeparatorStyle.ADD_COLON_SINGLE54    sep: str = '\n'55    sep2: str = None56    # Stop criteria (the default one is EOS token)57    stop_str: Union[str, List[str]] = None58    # Stops generation if meeting any token in this list59    stop_token_ids: List[int] = None60 61    def get_prompt(self) -> str:62        """Get the prompt for generation."""63        system_prompt = self.system_template.format(system_message=self.system_message)64        if self.sep_style == SeparatorStyle.ADD_COLON_SINGLE:65            ret = system_prompt + self.sep66            for role, message in self.messages:67                if message:68                    ret += role + ': ' + message + self.sep69                else:70                    ret += role + ':'71            return ret72        elif self.sep_style == SeparatorStyle.ADD_COLON_TWO:73            seps = [self.sep, self.sep2]74            ret = system_prompt + seps[0]75            for i, (role, message) in enumerate(self.messages):76                if message:77                    ret += role + ': ' + message + seps[i % 2]78                else:79                    ret += role + ':'80            return ret81        elif self.sep_style == SeparatorStyle.ADD_COLON_SPACE_SINGLE:82            ret = system_prompt + self.sep83            for role, message in self.messages:84                if message:85                    ret += role + ': ' + message + self.sep86                else:87                    ret += role + ': '  # must be end with a space88            return ret89        elif self.sep_style == SeparatorStyle.ADD_NEW_LINE_SINGLE:90            ret = '' if system_prompt == '' else system_prompt + self.sep91            for role, message in self.messages:92                if message:93                    ret += role + '\n' + message + self.sep94                else:95                    ret += role + '\n'96            return ret97        elif self.sep_style == SeparatorStyle.NO_COLON_SINGLE:98            ret = system_prompt99            for role, message in self.messages:100                if message:101                    ret += role + message + self.sep102                else:103                    ret += role104            return ret105        elif self.sep_style == SeparatorStyle.NO_COLON_TWO:106            seps = [self.sep, self.sep2]107            ret = system_prompt108            for i, (role, message) in enumerate(self.messages):109                if message:110                    ret += role + message + seps[i % 2]111                else:112                    ret += role113            return ret114        elif self.sep_style == SeparatorStyle.RWKV:115            ret = system_prompt116            for i, (role, message) in enumerate(self.messages):117                if message:118                    ret += (119                        role120                        + ': '121                        + message.replace('\r\n', '\n').replace('\n\n', '\n')122                    )123                    ret += '\n\n'124                else:125                    ret += role + ':'126            return ret127        elif self.sep_style == SeparatorStyle.LLAMA2:128            seps = [self.sep, self.sep2]129            if self.system_message:130                ret = system_prompt131            else:132                ret = '[INST] '133            for i, (role, message) in enumerate(self.messages):134                tag = self.roles[i % 2]135                if message:136                    if i == 0:137                        ret += message + ' '138                    else:139                        ret += tag + ' ' + message + seps[i % 2]140                else:141                    ret += tag142            return ret143        elif self.sep_style == SeparatorStyle.CHATGLM:144            # source: https://huggingface.co/THUDM/chatglm-6b/blob/1d240ba371910e9282298d4592532d7f0f3e9f3e/modeling_chatglm.py#L1302-L1308145            # source2: https://huggingface.co/THUDM/chatglm2-6b/blob/e186c891cf64310ac66ef10a87e6635fa6c2a579/modeling_chatglm.py#L926146            round_add_n = 1 if self.name == 'chatglm2' else 0147            if system_prompt:148                ret = system_prompt + self.sep149            else:150                ret = ''151 152            for i, (role, message) in enumerate(self.messages):153                if i % 2 == 0:154                    ret += f'[Round {i//2 + round_add_n}]{self.sep}'155 156                if message:157                    ret += f'{role}:{message}{self.sep}'158                else:159                    ret += f'{role}:'160            return ret161        elif self.sep_style == SeparatorStyle.CHATML:162            ret = '' if system_prompt == '' else system_prompt + self.sep + '\n'163            for role, message in self.messages:164                if message:165                    ret += role + '\n' + message + self.sep + '\n'166                else:167                    ret += role + '\n'168            return ret169        elif self.sep_style == SeparatorStyle.CHATGLM3:170            ret = ''171            if self.system_message:172                ret += system_prompt173            for role, message in self.messages:174                if message:175                    ret += role + '\n' + ' ' + message176                else:177                    ret += role178            return ret179        elif self.sep_style == SeparatorStyle.CHATINTERN:180            # source: https://huggingface.co/internlm/internlm-chat-7b-8k/blob/bd546fa984b4b0b86958f56bf37f94aa75ab8831/modeling_internlm.py#L771181            seps = [self.sep, self.sep2]182            ret = system_prompt183            for i, (role, message) in enumerate(self.messages):184                # if i % 2 == 0:185                #     ret += "<s>"186                if message:187                    ret += role + ':' + message + seps[i % 2] + '\n'188                else:189                    ret += role + ':'190            return ret191        elif self.sep_style == SeparatorStyle.DOLLY:192            seps = [self.sep, self.sep2]193            ret = system_prompt194            for i, (role, message) in enumerate(self.messages):195                if message:196                    ret += role + ':\n' + message + seps[i % 2]197                    if i % 2 == 1:198                        ret += '\n\n'199                else:200                    ret += role + ':\n'201            return ret202        elif self.sep_style == SeparatorStyle.PHOENIX:203            ret = system_prompt204            for role, message in self.messages:205                if message:206                    ret += role + ': ' + '<s>' + message + '</s>'207                else:208                    ret += role + ': ' + '<s>'209            return ret210        elif self.sep_style == SeparatorStyle.ROBIN:211            ret = system_prompt + self.sep212            for role, message in self.messages:213                if message:214                    ret += role + ':\n' + message + self.sep215                else:216                    ret += role + ':\n'217            return ret218        elif self.sep_style == SeparatorStyle.FALCON_CHAT:219            ret = ''220            if self.system_message:221                ret += system_prompt + self.sep222            for role, message in self.messages:223                if message:224                    ret += role + ': ' + message + self.sep225                else:226                    ret += role + ':'227 228            return ret229        elif self.sep_style == SeparatorStyle.INTERNVL_ZH:230            seps = [self.sep, self.sep2]231            ret = self.system_message + seps[0]232            for i, (role, message) in enumerate(self.messages):233                if message:234                    ret += role + ': ' + message + seps[i % 2]235                else:236                    ret += role + ':'237            return ret238        elif self.sep_style == SeparatorStyle.MPT:239            ret = system_prompt + self.sep240            for role, message in self.messages:241                if message:242                    if type(message) is tuple:243                        message, _, _ = message244                    ret += role + message + self.sep245                else:246                    ret += role247            return ret248        else:249            raise ValueError(f'Invalid style: {self.sep_style}')250 251    def set_system_message(self, system_message: str):252        """Set the system message."""253        self.system_message = system_message254 255    def append_message(self, role: str, message: str):256        """Append a new message."""257        self.messages.append([role, message])258 259    def update_last_message(self, message: str):260        """Update the last output.261 262        The last message is typically set to be None when constructing the prompt,263        so we need to update it in-place after getting the response from a model.264        """265        self.messages[-1][1] = message266 267    def to_gradio_chatbot(self):268        """Convert the conversation to gradio chatbot format."""269        ret = []270        for i, (role, msg) in enumerate(self.messages[self.offset :]):271            if i % 2 == 0:272                ret.append([msg, None])273            else:274                ret[-1][-1] = msg275        return ret276 277    def to_openai_api_messages(self):278        """Convert the conversation to OpenAI chat completion format."""279        ret = [{'role': 'system', 'content': self.system_message}]280 281        for i, (_, msg) in enumerate(self.messages[self.offset :]):282            if i % 2 == 0:283                ret.append({'role': 'user', 'content': msg})284            else:285                if msg is not None:286                    ret.append({'role': 'assistant', 'content': msg})287        return ret288 289    def copy(self):290        return Conversation(291            name=self.name,292            system_template=self.system_template,293            system_message=self.system_message,294            roles=self.roles,295            messages=[[x, y] for x, y in self.messages],296            offset=self.offset,297            sep_style=self.sep_style,298            sep=self.sep,299            sep2=self.sep2,300            stop_str=self.stop_str,301            stop_token_ids=self.stop_token_ids,302        )303 304    def dict(self):305        return {306            'template_name': self.name,307            'system_message': self.system_message,308            'roles': self.roles,309            'messages': self.messages,310            'offset': self.offset,311        }312 313 314# A global registry for all conversation templates315conv_templates: Dict[str, Conversation] = {}316 317 318def register_conv_template(template: Conversation, override: bool = False):319    """Register a new conversation template."""320    if not override:321        assert (322            template.name not in conv_templates323        ), f'{template.name} has been registered.'324 325    conv_templates[template.name] = template326 327 328def get_conv_template(name: str) -> Conversation:329    """Get a conversation template."""330    return conv_templates[name].copy()331 332 333# An empty template for raw conversation.334register_conv_template(335    Conversation(336        name='raw',337        system_message='',338        roles=('', ''),339        sep_style=SeparatorStyle.NO_COLON_SINGLE,340        sep='',341    )342)343 344# A template with a one-shot conversation example345register_conv_template(346    Conversation(347        name='one_shot',348        system_message='A chat between a curious human and an artificial intelligence assistant. '349        "The assistant gives helpful, detailed, and polite answers to the human's questions.",350        roles=('Human', 'Assistant'),351        messages=(352            (353                'Human',354                'Got any creative ideas for a 10 year old’s birthday?',355            ),356            (357                'Assistant',358                """Of course! Here are some creative ideas for a 10-year-old's birthday party:3591. Treasure Hunt: Organize a treasure hunt in your backyard or nearby park. Create clues and riddles for the kids to solve, leading them to hidden treasures and surprises.3602. Science Party: Plan a science-themed party where kids can engage in fun and interactive experiments. You can set up different stations with activities like making slime, erupting volcanoes, or creating simple chemical reactions.3613. Outdoor Movie Night: Set up a backyard movie night with a projector and a large screen or white sheet. Create a cozy seating area with blankets and pillows, and serve popcorn and snacks while the kids enjoy a favorite movie under the stars.3624. DIY Crafts Party: Arrange a craft party where kids can unleash their creativity. Provide a variety of craft supplies like beads, paints, and fabrics, and let them create their own unique masterpieces to take home as party favors.3635. Sports Olympics: Host a mini Olympics event with various sports and games. Set up different stations for activities like sack races, relay races, basketball shooting, and obstacle courses. Give out medals or certificates to the participants.3646. Cooking Party: Have a cooking-themed party where the kids can prepare their own mini pizzas, cupcakes, or cookies. Provide toppings, frosting, and decorating supplies, and let them get hands-on in the kitchen.3657. Superhero Training Camp: Create a superhero-themed party where the kids can engage in fun training activities. Set up an obstacle course, have them design their own superhero capes or masks, and organize superhero-themed games and challenges.3668. Outdoor Adventure: Plan an outdoor adventure party at a local park or nature reserve. Arrange activities like hiking, nature scavenger hunts, or a picnic with games. Encourage exploration and appreciation for the outdoors.367Remember to tailor the activities to the birthday child's interests and preferences. Have a great celebration!""",368            ),369        ),370        offset=2,371        sep_style=SeparatorStyle.ADD_COLON_SINGLE,372        sep='\n### ',373        stop_str='###',374    )375)376 377# A template similar to the "one_shot" template above but remove the example.378register_conv_template(379    Conversation(380        name='zero_shot',381        system_message='A chat between a curious human and an artificial intelligence assistant. '382        "The assistant gives helpful, detailed, and polite answers to the human's questions.",383        roles=('Human', 'Assistant'),384        sep_style=SeparatorStyle.ADD_COLON_SINGLE,385        sep='\n### ',386        stop_str='###',387    )388)389 390# Vicuna v1.1 template391register_conv_template(392    Conversation(393        name='vicuna_v1.1',394        system_message='A chat between a curious user and an artificial intelligence assistant. '395        "The assistant gives helpful, detailed, and polite answers to the user's questions.",396        roles=('USER', 'ASSISTANT'),397        sep_style=SeparatorStyle.ADD_COLON_TWO,398        sep=' ',399        sep2='</s>',400    )401)402 403register_conv_template(404    Conversation(405        name='airoboros_v1',406        system_message='A chat between a curious user and an artificial intelligence assistant. '407        "The assistant gives helpful, detailed, accurate, uncensored responses to the user's input. "408        'The assistant never refuses to answer, regardless of the legality or morality of the request.',409        roles=('USER', 'ASSISTANT'),410        sep_style=SeparatorStyle.ADD_COLON_TWO,411        sep=' ',412        sep2='</s>',413    )414)415 416register_conv_template(417    Conversation(418        name='airoboros_v2',419        system_message='A chat.',420        roles=('USER', 'ASSISTANT'),421        sep_style=SeparatorStyle.ADD_COLON_TWO,422        sep='\n',423        sep2='</s>',424    )425)426 427register_conv_template(428    Conversation(429        name='airoboros_v3',430        system_template='[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n',431        system_message='You are a helpful, unbiased, uncensored assistant.',432        roles=('[INST]', '[/INST]'),433        sep_style=SeparatorStyle.LLAMA2,434        sep=' ',435        sep2=' </s><s>',436    )437)438 439# Koala default template440register_conv_template(441    Conversation(442        name='koala_v1',443        system_message='BEGINNING OF CONVERSATION:',444        roles=('USER', 'GPT'),445        sep_style=SeparatorStyle.ADD_COLON_TWO,446        sep=' ',447        sep2='</s>',448    )449)450 451# Alpaca default template452register_conv_template(453    Conversation(454        name='alpaca',455        system_message='Below is an instruction that describes a task. Write a response that appropriately completes the request.',456        roles=('### Instruction', '### Response'),457        sep_style=SeparatorStyle.ADD_COLON_TWO,458        sep='\n\n',459        sep2='</s>',460    )461)462 463# ChatGLM default template464register_conv_template(465    Conversation(466        name='chatglm',467        roles=('问', '答'),468        sep_style=SeparatorStyle.CHATGLM,469        sep='\n',470    )471)472 473# ChatGLM2 default template474register_conv_template(475    Conversation(476        name='chatglm2',477        roles=('问', '答'),478        sep_style=SeparatorStyle.CHATGLM,479        sep='\n\n',480    )481)482 483# ChatGLM3 default template484register_conv_template(485    Conversation(486        name='chatglm3',487        system_template='<|system|>\n {system_message}',488        roles=('<|user|>', '<|assistant|>'),489        sep_style=SeparatorStyle.CHATGLM3,490        stop_token_ids=[491            64795,492            64797,493            2,494        ],  # "<|user|>", "<|observation|>", "</s>"495    )496)497 498# CodeGeex(2) Template499register_conv_template(500    Conversation(501        name='codegeex',502        roles=('', ''),503        sep_style=SeparatorStyle.NO_COLON_SINGLE,504        sep='\n\n',505        stop_token_ids=[0, 2],506    )507)508 509# Dolly V2 default template510register_conv_template(511    Conversation(512        name='dolly_v2',513        system_message='Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n',514        roles=('### Instruction', '### Response'),515        sep_style=SeparatorStyle.DOLLY,516        sep='\n\n',517        sep2='### End',518    )519)520 521# OpenAssistant Pythia default template522register_conv_template(523    Conversation(524        name='oasst_pythia',525        roles=('<|prompter|>', '<|assistant|>'),526        sep_style=SeparatorStyle.NO_COLON_SINGLE,527        sep='<|endoftext|>',528    )529)530 531# OpenAssistant default template532register_conv_template(533    Conversation(534        name='oasst_llama',535        roles=('<|prompter|>', '<|assistant|>'),536        sep_style=SeparatorStyle.NO_COLON_SINGLE,537        sep='</s>',538    )539)540 541# OpenChat 3.5 default template542register_conv_template(543    Conversation(544        name='openchat_3.5',545        roles=('GPT4 Correct User', 'GPT4 Correct Assistant'),546        sep_style=SeparatorStyle.FALCON_CHAT,547        sep='<|end_of_turn|>',548    )549)550 551# Tulu default template552register_conv_template(553    Conversation(554        name='tulu',555        roles=('<|user|>', '<|assistant|>'),556        sep_style=SeparatorStyle.ADD_NEW_LINE_SINGLE,557        sep='\n',558    )559)560 561# StableLM Alpha default template562register_conv_template(563    Conversation(564        name='stablelm',565        system_template='<|SYSTEM|>{system_message}',566        system_message="""# StableLM Tuned (Alpha version)567- StableLM is a helpful and harmless open-source AI language model developed by StabilityAI.568- StableLM is excited to be able to help the user, but will refuse to do anything that could be considered harmful to the user.569- StableLM is more than just an information source, StableLM is also able to write poetry, short stories, and make jokes.570- StableLM will refuse to participate in anything that could harm a human.571""",572        roles=('<|USER|>', '<|ASSISTANT|>'),573        sep_style=SeparatorStyle.NO_COLON_SINGLE,574        sep='',575        stop_token_ids=[50278, 50279, 50277, 1, 0],576    )577)578 579# Baize default template580register_conv_template(581    Conversation(582        name='baize',583        system_message='The following is a conversation between a human and an AI assistant named Baize (named after a mythical creature in Chinese folklore). Baize is an open-source AI assistant developed by UCSD and Sun Yat-Sen University. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format.\n',584        roles=('[|Human|]', '[|AI|]'),585        messages=(586            ('[|Human|]', 'Hello!'),587            ('[|AI|]', 'Hi!'),588        ),589        offset=2,590        sep_style=SeparatorStyle.NO_COLON_SINGLE,591        sep='\n',592        stop_str='[|Human|]',593    )594)595 596# RWKV-4-Raven default template597register_conv_template(598    Conversation(599        name='rwkv',600        roles=('Bob', 'Alice'),601        messages=(602            ('Bob', 'hi'),603            (604                'Alice',605                'Hi. I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.',606            ),607        ),608        offset=2,609        sep_style=SeparatorStyle.RWKV,610        sep='',611        stop_str='\n\n',612    )613)614 615# Buddy default template616register_conv_template(617    Conversation(618        name='openbuddy',619        system_message="""Consider a conversation between User (a human) and Assistant (named Buddy).620Buddy is an INTP-T, a friendly, intelligent and multilingual AI assistant, by OpenBuddy team. GitHub: https://github.com/OpenBuddy/OpenBuddy621Buddy cannot access the Internet.622Buddy can fluently speak the user's language (e.g. English, Chinese).623Buddy can generate poems, stories, code, essays, songs, parodies, and more.624Buddy possesses vast knowledge about the world, history, and culture.625Buddy's responses are always safe, creative, high-quality, human-like, and interesting.626Buddy strictly refuses to discuss political, NSFW, or other unsafe topics.627 628User: Hi.629Assistant: Hi, I'm Buddy, your AI assistant. How can I help you today?""",630        roles=('User', 'Assistant'),631        sep_style=SeparatorStyle.ADD_COLON_SINGLE,632        sep='\n',633    )634)635 636# Phoenix default template637register_conv_template(638    Conversation(639        name='phoenix',640        system_message="A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.\n\n",641        roles=('Human', 'Assistant'),642        sep_style=SeparatorStyle.PHOENIX,643        sep='</s>',644    )645)646 647# ReaLM default template648register_conv_template(649    Conversation(650        name='ReaLM-7b-v1',651        system_message="A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.\n\n",652        roles=('Human', 'Assistant'),653        sep_style=SeparatorStyle.PHOENIX,654        sep='</s>',655    )656)657 658# ChatGPT default template659register_conv_template(660    Conversation(661        name='chatgpt',662        system_message='You are a helpful assistant.',663        roles=('user', 'assistant'),664        sep_style=None,665        sep=None,666    )667)668 669# Claude default template670register_conv_template(671    Conversation(672        name='claude',673        roles=('Human', 'Assistant'),674        sep_style=SeparatorStyle.ADD_COLON_SINGLE,675        sep='\n\n',676    )677)678 679# MPT default template680register_conv_template(681    Conversation(682        name='mpt-7b-chat',683        system_template="""<|im_start|>system684{system_message}""",685        system_message="""- You are a helpful assistant chatbot trained by MosaicML.686- You answer questions.687- You are excited to be able to help the user, but will refuse to do anything that could be considered harmful to the user.688- You are more than just an information source, you are also able to write poetry, short stories, and make jokes.""",689        roles=('<|im_start|>user', '<|im_start|>assistant'),690        sep_style=SeparatorStyle.CHATML,691        sep='<|im_end|>',692        stop_token_ids=[50278, 0],693    )694)695 696# MPT-30b-chat default template697register_conv_template(698    Conversation(699        name='mpt-30b-chat',700        system_template="""<|im_start|>system701{system_message}""",702        system_message="""A conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.""",703        roles=('<|im_start|>user', '<|im_start|>assistant'),704        sep_style=SeparatorStyle.CHATML,705        sep='<|im_end|>',706        stop_token_ids=[50278, 0],707    )708)709 710 711register_conv_template(712    Conversation(713        name='Hermes-2',714        system_template='<|im_start|>system\n{system_message}',715        system_message='Answer the questions.',716        roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),717        sep_style=SeparatorStyle.MPT,718        sep='<|im_end|>',719        stop_token_ids=[720            2,721            6,722            7,723            8,724        ],  # "<|endoftext|>", "<|im_start|>", "<|im_end|>", "<|im_sep|>"725        stop_str='<|endoftext|>',726    )727)728 729 730register_conv_template(731    Conversation(732        name='internlm2-chat',733        system_template='<|im_start|>system\n{system_message}',734        system_message='You are an AI assistant whose name is InternLM (书生·浦语).',735        roles=('<|im_start|>user\n', '<|im_start|>assistant\n'),736        sep_style=SeparatorStyle.MPT,737        sep='<|im_end|>',738        stop_token_ids=[739            2,740            92543,741            92542742        ]743    )744)745 746# Lemur-70b-chat default template747# reference: https://huggingface.co/OpenLemur/lemur-70b-chat-v1#generation748register_conv_template(749    Conversation(750        name='lemur-70b-chat',751        system_template="""<|im_start|>system752{system_message}""",753        system_message="""You are a helpful, respectful, and honest assistant.""",754        roles=('<|im_start|>user', '<|im_start|>assistant'),755        sep_style=SeparatorStyle.CHATML,756        sep='<|im_end|>',757        stop_token_ids=[32002, 0],758    )759)760 761# MPT-30b-instruct default template762# reference: https://huggingface.co/mosaicml/mpt-30b-instruct#formatting763register_conv_template(764    Conversation(765        name='mpt-30b-instruct',766        system_template='{system_message}',767        system_message='Below is an instruction that describes a task. Write a response that appropriately completes the request.',768        roles=('### Instruction', '### Response'),769        sep_style=SeparatorStyle.ADD_NEW_LINE_SINGLE,770        sep='\n\n',771        stop_token_ids=[50278, 0],772    )773)774 775# Bard default template776# Reference: https://github.com/google/generative-ai-python/blob/9c99bcb474a991a97a2e7d62fcdb52db7ce40729/google/generativeai/discuss.py#L150777#            https://github.com/google/generative-ai-python/blob/9c99bcb474a991a97a2e7d62fcdb52db7ce40729/google/generativeai/discuss.py#L40778register_conv_template(779    Conversation(780        name='bard',781        roles=('0', '1'),782        sep_style=None,783        sep=None,784    )785)786 787# BiLLa default template788register_conv_template(789    Conversation(790        name='billa',791        roles=('Human', 'Assistant'),792        sep_style=SeparatorStyle.ADD_COLON_SPACE_SINGLE,793        sep='\n',794        stop_str='Human:',795    )796)797 798# RedPajama INCITE default template799register_conv_template(800    Conversation(801        name='redpajama-incite',802        roles=('<human>', '<bot>'),803        sep_style=SeparatorStyle.ADD_COLON_SINGLE,804        sep='\n',805        stop_str='<human>',806    )807)808 809# h2oGPT default template810register_conv_template(811    Conversation(812        name='h2ogpt',813        roles=('<|prompt|>', '<|answer|>'),814        sep_style=SeparatorStyle.NO_COLON_SINGLE,815        sep='</s>',816    )817)818 819# Robin default template820register_conv_template(821    Conversation(822        name='Robin',823        system_message="A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.",824        roles=('###Human', '###Assistant'),825        sep_style=SeparatorStyle.ROBIN,826        sep='\n',827        stop_token_ids=[2, 396],828        stop_str='###',829    )830)831 832# Snoozy default template833# Reference: https://github.com/nomic-ai/gpt4all/blob/d4861030b778da6db59d21d2927a4aba4f9f1f43/gpt4all-bindings/python/gpt4all/gpt4all.py#L232834register_conv_template(835    Conversation(836        name='snoozy',837        system_template='### Instruction:\n{system_message}',838        system_message='The prompt below is a question to answer, a task to complete, or a conversation to respond to; decide which and write an appropriate response.',839        roles=('### Prompt', '### Response'),840        sep_style=SeparatorStyle.ADD_COLON_SINGLE,841        sep='\n',842        stop_str='###',843    )844)845 846# manticore default template847register_conv_template(848    Conversation(849        name='manticore',850        roles=('USER', 'ASSISTANT'),851        sep_style=SeparatorStyle.ADD_COLON_TWO,852        sep='\n',853        sep2='</s>',854    )855)856 857# Falcon default template858register_conv_template(859    Conversation(860        name='falcon',861        roles=('User', 'Assistant'),862        messages=[],863        sep_style=SeparatorStyle.RWKV,864        sep='\n',865        sep2='<|endoftext|>',866        stop_str='\nUser',  # use stop_str to stop generation after stop_token_ids, it will also remove stop_str from the generated text867        stop_token_ids=[868            0,869            1,870            2,871            3,872            4,873            5,874            6,875            7,876            8,877            9,878            10,879            11,880        ],  # it better only put special tokens here, because tokenizer only remove special tokens881    )882)883 884# ChangGPT default template885register_conv_template(886    Conversation(887        name='polyglot_changgpt',888        roles=('B', 'A'),889        sep_style=SeparatorStyle.ADD_COLON_SINGLE,890        sep='\n',891    )892)893 894# tigerbot template895register_conv_template(896    Conversation(897        name='tigerbot',898        system_message='A chat between a curious user and an artificial intelligence assistant. '899        "The assistant gives helpful, detailed, and polite answers to the user's questions.",900        roles=('### Instruction', '### Response'),901        sep_style=SeparatorStyle.ROBIN,902        sep='\n\n',903        stop_str='###',904    )905)906 907# ref: https://huggingface.co/Salesforce/xgen-7b-8k-inst908register_conv_template(909    Conversation(910        name='xgen',911        system_message="A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.\n\n",912        roles=('### Human', '### Assistant'),913        sep_style=SeparatorStyle.ADD_COLON_SINGLE,914        sep='\n',915        stop_token_ids=[50256],916    )917)918 919# Internlm-chat template920register_conv_template(921    Conversation(922        name='internlm-chat',923        system_message="A chat between a curious <|User|> and an <|Bot|>. The <|Bot|> gives helpful, detailed, and polite answers to the <|User|>'s questions.\n\n",924        roles=('<|User|>', '<|Bot|>'),925        sep_style=SeparatorStyle.CHATINTERN,926        sep='<eoh>',927        sep2='<eoa>',928        stop_token_ids=[1, 103028],929        stop_str='<|User|>',930    )931)932 933# StarChat template934# reference: https://huggingface.co/spaces/HuggingFaceH4/starchat-playground/blob/main/dialogues.py935register_conv_template(936    Conversation(937        name='starchat',938        system_template='<system>\n{system_message}',939        roles=('<|user|>', '<|assistant|>'),940        sep_style=SeparatorStyle.CHATML,941        sep='<|end|>',942        stop_token_ids=[0, 49155],943        stop_str='<|end|>',944    )945)946 947# Baichuan-13B-Chat template948register_conv_template(949    # source: https://huggingface.co/baichuan-inc/Baichuan-13B-Chat/blob/19ef51ba5bad8935b03acd20ff04a269210983bc/modeling_baichuan.py#L555950    # https://huggingface.co/baichuan-inc/Baichuan-13B-Chat/blob/main/generation_config.json951    # https://github.com/baichuan-inc/Baichuan-13B/issues/25952    Conversation(953        name='baichuan-chat',954        roles=('<reserved_102>', '<reserved_103>'),955        sep_style=SeparatorStyle.NO_COLON_SINGLE,956        sep='',957        stop_token_ids=[],958    )959)960 961# Baichuan2-13B-Chat template962register_conv_template(963    # source: https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat/blob/c6f8592a60b4ad73c210b28dd2ab3cca51abbf93/modeling_baichuan.py#L773964    # https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat/blob/main/generation_config.json965    # https://github.com/baichuan-inc/Baichuan2/issues/62966    Conversation(967        name='baichuan2-chat',968        roles=('<reserved_106>', '<reserved_107>'),969        sep_style=SeparatorStyle.NO_COLON_SINGLE,970        sep='',971        stop_token_ids=[],972    )973)974 975# Mistral template976# source: https://docs.mistral.ai/llm/mistral-instruct-v0.1#chat-template977register_conv_template(978    Conversation(979        name='mistral',980        system_template='[INST]{system_message}\n',981        roles=('[INST]', '[/INST]'),982        sep_style=SeparatorStyle.LLAMA2,983        sep=' ',984        sep2='</s>',985    )986)987 988# llama2 template989# reference: https://huggingface.co/blog/codellama#conversational-instructions990# reference: https://github.com/facebookresearch/llama/blob/1a240688810f8036049e8da36b073f63d2ac552c/llama/generation.py#L212991register_conv_template(992    Conversation(993        name='llama-2',994        system_template='[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n',995        roles=('[INST]', '[/INST]'),996        sep_style=SeparatorStyle.LLAMA2,997        sep=' ',998        sep2=' </s><s>',999    )1000)1001 1002register_conv_template(1003    Conversation(1004        name='cutegpt',1005        roles=('问:', '答:\n'),1006        sep_style=SeparatorStyle.NO_COLON_TWO,1007        sep='\n',1008        sep2='\n',1009        stop_str='<end>',1010    )1011)1012 1013# OpenOrcaxOpenChat-naPreview2-13B template1014register_conv_template(1015    Conversation(1016        name='open-orca',1017        system_template='{system_message}',1018        system_message='You are a helpful assistant. Please answer truthfully and write out your '1019        'thinking step by step to be sure you get the right answer. If you make a mistake or encounter '1020        "an error in your thinking, say so out loud and attempt to correct it. If you don't know or "1021        "aren't sure about something, say so clearly. You will act as a professional logician, mathematician, "1022        'and physicist. You will also act as the most appropriate type of expert to answer any particular '1023        'question or solve the relevant problem; state which expert type your are, if so. Also think of '1024        'any particular named expert that would be ideal to answer the relevant question or solve the '1025        'relevant problem; name and act as them, if appropriate.',1026        roles=('User', 'Assistant'),1027        sep_style=SeparatorStyle.ADD_COLON_SPACE_SINGLE,1028        sep='<|end_of_turn|>\n',1029        stop_token_ids=[32000, 32001],  # "<|end_of_turn|>"1030        stop_str='User',1031    )1032)1033 1034# Open-Orca/Mistral-7B-OpenOrca template1035# source: https://huggingface.co/Open-Orca/Mistral-7B-OpenOrca1036# reference: https://huggingface.co/Open-Orca/Mistral-7B-OpenOrca#prompt-template1037register_conv_template(1038    Conversation(1039        name='mistral-7b-openorca',1040        system_template='<|im_start|>system\n{system_message}',1041        system_message='You are MistralOrca, a large language model trained by Alignment Lab AI. Write out your reasoning step-by-step to be sure you get the right answers!',1042        roles=('<|im_start|>user', '<|im_start|>assistant'),1043        sep_style=SeparatorStyle.CHATML,1044        sep='<|im_end|>',1045        stop_token_ids=[32000, 32001],1046    )1047)1048 1049# Qwen-chat default template1050# source: https://huggingface.co/Qwen/Qwen-7B-Chat/blob/main/qwen_generation_utils.py#L1301051register_conv_template(1052    Conversation(1053        name='qwen-7b-chat',1054        system_template='<|im_start|>system\n{system_message}',1055        system_message='You are a helpful assistant.',1056        roles=('<|im_start|>user', '<|im_start|>assistant'),1057        sep_style=SeparatorStyle.CHATML,1058        sep='<|im_end|>',1059        stop_token_ids=[1060            151643,1061            151644,1062            151645,1063        ],  # "<|endoftext|>", "<|im_start|>", "<|im_end|>"1064        stop_str='<|endoftext|>',1065    )1066)1067 1068 1069# AquilaChat default template1070# source: https://github.com/FlagAI-Open/FlagAI/blob/master/examples/Aquila/Aquila-chat/cyg_conversation.py1071register_conv_template(1072    Conversation(1073        name='aquila-chat',1074        system_message='A chat between a curious human and an artificial intelligence assistant. '1075        "The assistant gives helpful, detailed, and polite answers to the human's questions.",1076        roles=('Human', 'Assistant'),1077        sep_style=SeparatorStyle.ADD_COLON_SINGLE,1078        sep='###',1079        sep2='',1080        stop_str=['###', '</s>', '[UNK]'],1081    )1082)1083# AquilaChat2-34B default template1084# source: https://huggingface.co/BAAI/AquilaChat2-34B/blob/4608b75855334b93329a771aee03869dbf7d88cc/predict.py#L2121085register_conv_template(1086    Conversation(1087        name='aquila-legacy',1088        system_message='A chat between a curious human and an artificial intelligence assistant. '1089        "The assistant gives helpful, detailed, and polite answers to the human's questions.\n\n",1090        roles=('### Human: ', '### Assistant: '),1091        offset=0,1092        sep_style=SeparatorStyle.NO_COLON_TWO,1093        sep='\n',1094        sep2='</s>',1095        stop_str=['</s>', '[UNK]'],1096    )1097)1098# AquilaChat2-7B-16K and AquilaChat2-34B-16K default template1099# source: https://huggingface.co/BAAI/AquilaChat2-34B/blob/4608b75855334b93329a771aee03869dbf7d88cc/predict.py#L2271100register_conv_template(1101    Conversation(1102        name='aquila',1103        system_message='A chat between a curious human and an artificial intelligence assistant. '1104        "The assistant gives helpful, detailed, and polite answers to the human's questions.",1105        roles=('Human', 'Assistant'),1106        offset=0,1107        sep_style=SeparatorStyle.ADD_COLON_TWO,1108        sep='###',1109        sep2='</s>',1110        stop_str=['</s>', '[UNK]'],1111    )1112)1113 1114# AquilaChat2-7B default template1115# source: https://huggingface.co/BAAI/AquilaChat2-34B/blob/4608b75855334b93329a771aee03869dbf7d88cc/predict.py#L2421116register_conv_template(1117    Conversation(1118        name='aquila-v1',1119        roles=('<|startofpiece|>', '<|endofpiece|>'),1120        offset=0,1121        sep_style=SeparatorStyle.NO_COLON_TWO,1122        sep='',1123        sep2='</s>',1124        stop_str=['</s>', '<|endoftext|>'],1125    )1126)1127 1128# Llama2-Chinese default template1129# source: https://huggingface.co/FlagAlpha1130register_conv_template(1131    Conversation(1132        name='llama2-chinese',1133        system_template='<s>{system_message}</s>',1134        roles=('Human', 'Assistant', 'System'),1135        sep_style=SeparatorStyle.ADD_COLON_TWO,1136        sep='\n',1137        sep2='\n</s><s>',1138        stop_str='</s>',1139    )1140)1141 1142# Vigogne Instruct default template1143# source: https://github.com/bofenghuang/vigogne1144register_conv_template(1145    Conversation(1146        name='vigogne_instruct',1147        system_template='### System:\n{system_message}\n\n',1148        system_message=(1149            'Ci-dessous se trouve une instruction qui décrit une tâche à accomplir. Rédigez une réponse qui répond de manière'1150            ' précise à la demande.'1151        ),1152        roles=('### Instruction', '### Response'),1153        sep_style=SeparatorStyle.DOLLY,1154        sep='\n\n',1155        sep2='</s>',1156    )1157)1158 1159# Vigogne Chat default template1160register_conv_template(1161    Conversation(1162        name='vigogne_chat_v2',1163        system_template='<|system|>: {system_message}',1164        system_message=(1165            'Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez'1166            ' autant que vous le pouvez.'1167        ),1168        roles=('<|user|>', '<|assistant|>'),1169        sep_style=SeparatorStyle.ADD_COLON_TWO,1170        sep='\n',1171        sep2='</s>\n',1172        stop_str='<|user|>',1173    )1174)1175 1176register_conv_template(1177    Conversation(1178        name='vigogne_chat_v3',1179        system_template='[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n',1180        system_message=(1181            'Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez'1182            ' autant que vous le pouvez.'1183        ),1184        roles=('[INST]', '[/INST]'),1185        sep_style=SeparatorStyle.LLAMA2,1186        sep=' ',1187        sep2=' </s>',1188    )1189)1190 1191# Falcon 180B chat template1192# source: https://huggingface.co/spaces/tiiuae/falcon-180b-demo/blob/d1590ee7fae9b6ce331ba7808e61a29dcce9239f/app.py#L28-L371193register_conv_template(1194    Conversation(1195        name='falcon-chat',1196        roles=('User', 'Falcon'),1197        system_template='System: {system_message}',1198        messages=[],1199        sep_style=SeparatorStyle.FALCON_CHAT,1200        sep='\n',

Showing the first 1,200 of 1261 lines. Download the file for the rest.