Map Hermes reasoning controls into Qwen templates

This commit is contained in:
Mikei386
2026-08-25 14:52:43 +02:00
parent 7df28d9750
commit 63fc921988
6 changed files with 149 additions and 2 deletions
+50
View File
@@ -27,6 +27,7 @@ from ai_profile_router import ( # noqa: E402
_context_matches,
_normalize_chat_image,
_normalize_chat_images,
_normalize_llamacpp_reasoning,
_request_has_image,
)
@@ -126,6 +127,55 @@ class ChatImageInputTests(unittest.TestCase):
self.assertEqual(request, normalized)
class LlamaCppReasoningTests(unittest.TestCase):
def test_none_really_disables_thinking(self) -> None:
request = {"reasoning_effort": "none", "messages": []}
normalized = _normalize_llamacpp_reasoning(request)
self.assertNotIn("reasoning_effort", normalized)
self.assertEqual(
normalized["chat_template_kwargs"],
{"enable_thinking": False},
)
def test_low_and_medium_reach_chat_template(self) -> None:
for effort in ("low", "medium"):
with self.subTest(effort=effort):
request = {"reasoning_effort": effort, "messages": []}
normalized = _normalize_llamacpp_reasoning(request)
self.assertEqual(normalized["chat_template_kwargs"], {
"enable_thinking": True,
"reasoning_effort": effort,
})
def test_unsupported_high_levels_are_clamped_to_xhigh(self) -> None:
for effort in ("high", "xhigh", "max", "ultra"):
with self.subTest(effort=effort):
request = {"reasoning_effort": effort, "messages": []}
normalized = _normalize_llamacpp_reasoning(request)
self.assertEqual(
normalized["chat_template_kwargs"]["reasoning_effort"],
"xhigh",
)
def test_existing_template_kwargs_are_preserved(self) -> None:
request = {
"reasoning_effort": "low",
"chat_template_kwargs": {"preserve_thinking": True},
"messages": [],
}
normalized = _normalize_llamacpp_reasoning(request)
self.assertEqual(normalized["chat_template_kwargs"], {
"preserve_thinking": True,
"enable_thinking": True,
"reasoning_effort": "low",
})
def test_request_without_effort_is_unchanged(self) -> None:
request = {"messages": []}
self.assertIs(_normalize_llamacpp_reasoning(request), request)
self.assertNotIn("chat_template_kwargs", request)
class RetentionTests(unittest.TestCase):
def test_oldest_pairs_are_removed(self) -> None:
with tempfile.TemporaryDirectory() as temp: