Get the chat template for the model. Args: model_path (str): the model path. config (ChatTemplateConfig | None): the chat template config. trust_remote_code (bool): whether to trust remote code. Returns: BaseChatTemplate: the chat template.
(model_path: str, config: ChatTemplateConfig | None = None,
trust_remote_code: bool = False)
| 809 | |
| 810 | |
| 811 | def get_chat_template(model_path: str, config: ChatTemplateConfig | None = None, |
| 812 | trust_remote_code: bool = False) -> BaseChatTemplate: |
| 813 | """Get the chat template for the model. |
| 814 | |
| 815 | Args: |
| 816 | model_path (str): the model path. |
| 817 | config (ChatTemplateConfig | None): the chat template config. |
| 818 | trust_remote_code (bool): whether to trust remote code. |
| 819 | Returns: |
| 820 | BaseChatTemplate: the chat template. |
| 821 | """ |
| 822 | if config is not None: |
| 823 | return config.chat_template(trust_remote_code=trust_remote_code) |
| 824 | chat_template_name = 'base' |
| 825 | for name, model in MODELS.module_dict.items(): |
| 826 | if model.match(model_path, trust_remote_code=trust_remote_code): |
| 827 | chat_template_name = name |
| 828 | break |
| 829 | config = ChatTemplateConfig(chat_template_name, model_path=model_path) |
| 830 | return config.chat_template(trust_remote_code=trust_remote_code) |
no test coverage detected