24 lines
791 B
Python
24 lines
791 B
Python
import secrets
|
|
|
|
from google.genai import types
|
|
|
|
|
|
def fresh_seed(previous: int | None = None) -> int:
|
|
"""Choose a random int32 seed, excluding the preceding attempt's seed."""
|
|
limit = 2**31
|
|
if previous is None:
|
|
return secrets.randbelow(limit)
|
|
return (previous + 1 + secrets.randbelow(limit - 1)) % limit
|
|
|
|
|
|
def thinking_config(level: str | None) -> types.ThinkingConfig | None:
|
|
"""Use a supported reasoning level, or omit it for the model default."""
|
|
if level is None:
|
|
return None
|
|
if level not in {"minimal", "low", "medium", "high"}:
|
|
raise ValueError(
|
|
f"Invalid Gemini thinking level {level!r}; "
|
|
'expected "minimal", "low", "medium", "high", or None'
|
|
)
|
|
return types.ThinkingConfig(thinking_level=level)
|