Spaces:
Sleeping
Sleeping
File size: 3,614 Bytes
61bb677 a1bab2d 61bb677 a1bab2d 61bb677 c1b027b 61bb677 c1b027b 61bb677 c1b027b 61bb677 | 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | """Provider-neutral reasoning intent."""
from __future__ import annotations
from dataclasses import dataclass
from enum import StrEnum
class ReasoningControl(StrEnum):
"""Whether a request explicitly controls reasoning computation."""
DEFAULT = "default"
OFF = "off"
ON = "on"
class ReasoningEffort(StrEnum):
"""Named reasoning effort understood at the FCC application boundary."""
MINIMAL = "minimal"
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
XHIGH = "xhigh"
MAX = "max"
@property
def budget_tokens(self) -> int:
"""Return FCC's numeric token budget for this effort."""
return _EFFORT_BUDGET_TOKENS[self]
_EFFORT_BUDGET_TOKENS = {
ReasoningEffort.MINIMAL: 512,
ReasoningEffort.LOW: 512,
ReasoningEffort.MEDIUM: 1_024,
ReasoningEffort.HIGH: 2_048,
ReasoningEffort.XHIGH: 4_096,
ReasoningEffort.MAX: 8_192,
}
@dataclass(frozen=True, slots=True)
class ReasoningPolicy:
"""Resolved client and configuration intent passed to one provider.
``control`` and ``effort`` remain independent because clients may set an
overall effort while separately disabling extended thinking. Providers
translate the representable subset without changing the original intent.
"""
control: ReasoningControl = ReasoningControl.DEFAULT
effort: ReasoningEffort | None = None
budget_tokens: int | None = None
def __post_init__(self) -> None:
if self.budget_tokens is not None and (
not isinstance(self.budget_tokens, int)
or isinstance(self.budget_tokens, bool)
or self.budget_tokens <= 0
):
raise ValueError("Reasoning budget must be a positive integer.")
if self.budget_tokens is not None and self.control is not ReasoningControl.ON:
raise ValueError("A reasoning budget requires reasoning control to be on.")
@classmethod
def provider_default(cls) -> "ReasoningPolicy":
"""Leave reasoning computation to the provider."""
return cls()
@classmethod
def off(cls) -> "ReasoningPolicy":
"""Explicitly disable reasoning computation and output."""
return cls(control=ReasoningControl.OFF)
@classmethod
def on(
cls,
*,
effort: ReasoningEffort | None = None,
budget_tokens: int | None = None,
) -> "ReasoningPolicy":
"""Explicitly enable reasoning with optional client controls."""
return cls(
control=ReasoningControl.ON,
effort=effort,
budget_tokens=budget_tokens,
)
@property
def output_enabled(self) -> bool:
"""Return whether provider reasoning may be exposed to the client."""
return self.control is not ReasoningControl.OFF
@property
def requests_reasoning(self) -> bool:
"""Return whether the request explicitly asks the provider to reason."""
return self.control is not ReasoningControl.OFF and (
self.control is ReasoningControl.ON
or self.effort is not None
or self.budget_tokens is not None
)
@property
def numeric_budget_tokens(self) -> int | None:
"""Express this intent as an exact or FCC-mapped numeric budget."""
if self.control is ReasoningControl.OFF:
return None
if self.budget_tokens is not None:
return self.budget_tokens
if self.effort is None:
return None
return self.effort.budget_tokens
DEFAULT_REASONING_POLICY = ReasoningPolicy.provider_default()
|