main
py 32 lines 1.06 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import enum
5 from typing import Literal
6
7 ToolStrictLevelName = Literal["auto", "function", "parameter"]
8
9
10 class ToolStrictLevel(enum.IntEnum):
11 """Server-side floor for tool-call structural tags (``--tool-strict-level``).
12
13 AUTO: derive call constraints from ``tool_choice`` and argument-schema
14 enforcement from each tool's explicit ``strict`` field.
15 FUNCTION: constrain the tool-call envelope for every request with tools.
16 PARAMETER: additionally pin argument schemas, as if every tool were
17 ``strict: true``.
18 """
19
20 AUTO = 0
21 FUNCTION = 1
22 PARAMETER = 2
23
24 @classmethod
25 def from_name(cls, name: str) -> "ToolStrictLevel":
26 try:
27 return cls[name.strip().upper()]
28 except KeyError:
29 expected = ", ".join(level.name.lower() for level in cls)
30 raise ValueError(
31 f"Unknown tool strict level {name!r}; expected one of {expected}."
32 ) from None