Skip to content

anthropic_utils

SAMPLING_PARAMS_DEPRECATED_MIN_VERSIONS = {'opus': (4, 7), 'sonnet': (5, 0)} module-attribute

_CLAUDE_VERSION_PATTERN = re.compile('claude-([a-z]+)-(\\d+)(?:-(\\d{1,2})(?!\\d))?') module-attribute

supports_sampling_params(model)

Whether a Claude model accepts the temperature, top_p, and top_k sampling parameters.

Support is derived from the Claude model family and version embedded in model rather than a hardcoded model id, so every model in an affected family at or above the deprecating version (for example every Opus release from 4.7 onward, including major-only ids like claude-opus-5) is covered without a per-model change. A model whose minor version is absent is treated as .0.

Source code in griptape/utils/anthropic_utils.py
def supports_sampling_params(model: str) -> bool:
    """Whether a Claude model accepts the temperature, top_p, and top_k sampling parameters.

    Support is derived from the Claude model family and version embedded in ``model`` rather than a
    hardcoded model id, so every model in an affected family at or above the deprecating version
    (for example every Opus release from 4.7 onward, including major-only ids like ``claude-opus-5``)
    is covered without a per-model change. A model whose minor version is absent is treated as ``.0``.
    """
    match = _CLAUDE_VERSION_PATTERN.search(model)
    if match is None:
        return True

    family, major = match.group(1), int(match.group(2))
    minor = int(match.group(3)) if match.group(3) is not None else 0
    min_deprecated_version = SAMPLING_PARAMS_DEPRECATED_MIN_VERSIONS.get(family)

    return min_deprecated_version is None or (major, minor) < min_deprecated_version