Guided decoding parameters for text generation. Only one of the fields could be effective. Args: json (str, pydantic.main.BaseModel, dict, optional): The generated text is amenable to json format with additional user-specified restrictions, namely schema. Defaults to None. regex
| 13 | |
| 14 | @dataclass(slots=True, kw_only=True) |
| 15 | class GuidedDecodingParams: |
| 16 | """Guided decoding parameters for text generation. Only one of the fields could be effective. |
| 17 | |
| 18 | Args: |
| 19 | json (str, pydantic.main.BaseModel, dict, optional): The generated text is amenable to json format with additional user-specified restrictions, namely schema. Defaults to None. |
| 20 | regex (str, optional): The generated text is amenable to the user-specified regular expression. Defaults to None. |
| 21 | grammar (str, optional): The generated text is amenable to the user-specified extended Backus-Naur form (EBNF) grammar. Defaults to None. |
| 22 | json_object (bool): If True, the generated text is amenable to json format. Defaults to False. |
| 23 | structural_tag (str, optional): The generated text is amenable to the user-specified structural tag. Structural tag is supported by xgrammar backend only. Defaults to None. |
| 24 | """ # noqa: E501 |
| 25 | |
| 26 | json: Optional[Union[str, BaseModel, dict]] = None |
| 27 | regex: Optional[str] = None |
| 28 | grammar: Optional[str] = None |
| 29 | json_object: bool = False |
| 30 | structural_tag: Optional[str] = None |
| 31 | |
| 32 | def _validate(self): |
| 33 | num_guides = 0 |
| 34 | for _field in fields(self): |
| 35 | num_guides += bool(getattr(self, _field.name)) |
| 36 | if num_guides > 1: |
| 37 | raise ValueError(f"Only one guide can be used for a request, but got {num_guides}.") |
| 38 | |
| 39 | |
| 40 | class LogprobParams(NamedTuple): |
no outgoing calls