Spaces:
Running
Running
File size: 1,242 Bytes
f209a8f a58ab5d f209a8f a58ab5d f209a8f | 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 39 40 | import re
from typing import Any
_MODEL_NAME_SPLIT_RE = re.compile(r"[/:\s]+")
def model_rejects_sampling_params(model_name: str) -> bool:
normalized = str(model_name or "").strip().casefold()
if not normalized:
return False
parts = [part for part in _MODEL_NAME_SPLIT_RE.split(normalized) if part]
return any(part.startswith("claude") for part in parts)
def model_rejects_presence_penalty(model_name: str) -> bool:
normalized = str(model_name or "").strip().casefold()
if not normalized:
return False
parts = [part for part in _MODEL_NAME_SPLIT_RE.split(normalized) if part]
return any(part.startswith("gpt-5.5") for part in parts)
def apply_sampling_params(
request_kwargs: dict[str, Any],
*,
model_name: str,
temperature: Any = None,
top_p: Any = None,
presence_penalty: Any = None,
) -> None:
if model_rejects_sampling_params(model_name):
return
if temperature is not None:
request_kwargs["temperature"] = temperature
if top_p is not None:
request_kwargs["top_p"] = top_p
if presence_penalty is not None and not model_rejects_presence_penalty(model_name):
request_kwargs["presence_penalty"] = presence_penalty
|