File size: 1,450 Bytes
0a72c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from mmcm.utils.str_util import has_key_brace

from .human import PortraitAttr2PromptTemplate
from .attributes.attr2template import (
    KeywordMultiAttr2PromptTemplate,
    OnlySpacePromptTemplate,
)


def get_template_by_name(template: str, name: str = None):
    """根据 template_name 确定 prompt 生成器类
        choose prompt generator class according to template_name
    Args:
        name (str): template 的名字简称,便于指定. template name abbreviation, for easy reference

    Raises:
        ValueError: ValueError: 如果name不在支持的列表中,则报错. if name is not in the supported list, an error is reported.

    Returns:
        MultiAttr2PromptTemplate: 能够将任务字典转化为提词的 实现了__call__功能的类. class that can convert task dictionaries into prompts and implements the __call__ function

    """
    if template == "" or template is None:
        template = OnlySpacePromptTemplate(template=template)
    elif has_key_brace(template):
        # if has_key_brace(template):
        template = KeywordMultiAttr2PromptTemplate(template=template)
    else:
        if name == "portrait":
            template = PortraitAttr2PromptTemplate(templates=template)
        else:
            raise ValueError(
                "PresetAttr2PromptTemplate only support one of [portrait], but given {}".format(
                    name
                )
            )
    return template