Fix Inkling reasoning-effort coercion for duck-typed engine stand-ins (#7158)

* Make the Inkling reasoning-effort coercion a module-level helper so duck-typed engine stand-ins keep working

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Align Inkling minimal reasoning effort with the reference implementation (0.1)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Daniel Han 2026-07-16 06:23:06 -07:00 committed by GitHub
commit 030f12753c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1541,6 +1541,31 @@ def _is_external_link(path: Path) -> bool:
return False
# Inkling's template takes a numeric thinking-effort dial (0..0.99) and its
# float() coercion turns unrecognized named levels into 0, i.e. no thinking.
# Map OpenAI-style names to the values the model was trained on. Module-level
# so duck-typed engine stand-ins in tests do not need the attribute.
_INKLING_REASONING_EFFORT = {
"none": 0.0,
"minimal": 0.1,
"low": 0.2,
"medium": 0.7,
"high": 0.9,
"xhigh": 0.99,
"max": 0.99,
}
def _coerce_reasoning_effort(architecture, kwargs: dict) -> dict:
if architecture == "inkling":
effort = kwargs.get("reasoning_effort")
if isinstance(effort, str):
mapped = _INKLING_REASONING_EFFORT.get(effort.strip().lower())
if mapped is not None:
kwargs["reasoning_effort"] = mapped
return kwargs
class LlamaCppBackend:
"""Manages a llama-server subprocess for GGUF model inference.
@ -1941,36 +1966,15 @@ class LlamaCppBackend:
def reasoning_default(self) -> bool:
return self._reasoning_default
# Inkling's template takes a numeric thinking-effort dial (0..0.99) and its
# float() coercion turns unrecognized named levels into 0, i.e. no thinking.
# Map OpenAI-style names to the values the model was trained on.
_INKLING_REASONING_EFFORT = {
"none": 0.0,
"minimal": 0.2,
"low": 0.2,
"medium": 0.7,
"high": 0.9,
"xhigh": 0.99,
"max": 0.99,
}
def _coerce_reasoning_effort(self, kwargs: dict) -> dict:
if getattr(self, "_architecture", None) == "inkling":
effort = kwargs.get("reasoning_effort")
if isinstance(effort, str):
mapped = self._INKLING_REASONING_EFFORT.get(effort.strip().lower())
if mapped is not None:
kwargs["reasoning_effort"] = mapped
return kwargs
def _reasoning_kwargs(self, enable_thinking: bool) -> dict:
if self._reasoning_style == "enable_thinking_effort":
# GLM-5.2-style: enable_thinking is the on/off gate; when on, leave
# the template's default effort (max) in place.
return {"enable_thinking": enable_thinking}
if self._reasoning_style == "reasoning_effort":
return self._coerce_reasoning_effort(
{"reasoning_effort": "high" if enable_thinking else "low"}
return _coerce_reasoning_effort(
getattr(self, "_architecture", None),
{"reasoning_effort": "high" if enable_thinking else "low"},
)
return {"enable_thinking": enable_thinking}
@ -2019,7 +2023,7 @@ class LlamaCppBackend:
kwargs["enable_thinking"] = enable_thinking
if self._supports_preserve_thinking and preserve_thinking is not None:
kwargs["preserve_thinking"] = preserve_thinking
self._coerce_reasoning_effort(kwargs)
_coerce_reasoning_effort(getattr(self, "_architecture", None), kwargs)
return kwargs or None
@property