MCPcopy
hub / github.com/InternLM/lmdeploy / get_chat_template

Function get_chat_template

lmdeploy/model.py:811–830  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

809
810
811def 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)

Callers 1

__init__Method · 0.90

Calls 4

chat_templateMethod · 0.95
ChatTemplateConfigClass · 0.85
itemsMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected