[Bugfix][Frontend] Apply output_config and thinking in Anthropic count_tokens (#59180)
Signed-off-by: Kang Nahoon <ejrtks102020@gmail.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
co-authored by
Flora Feng
parent
1283362e76
commit
1995c0fcd0
@@ -1987,6 +1987,32 @@ class TestThinkingConfig:
|
||||
assert result.include_reasoning is True
|
||||
assert result.thinking_token_budget is None
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config",
|
||||
[
|
||||
pytest.param({"output_config": {"effort": "low"}}, id="effort"),
|
||||
pytest.param({"thinking": {"type": "disabled"}}, id="disabled"),
|
||||
pytest.param(
|
||||
{"thinking": {"type": "enabled", "budget_tokens": 2048}},
|
||||
id="enabled",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_count_tokens_matches_messages(self, config):
|
||||
"""Effort and thinking change the rendered prompt, so count_tokens must
|
||||
apply them the same way /v1/messages does."""
|
||||
messages = [{"role": "user", "content": "Hello"}]
|
||||
expected = _convert(
|
||||
AnthropicMessagesRequest(
|
||||
model="test-model", max_tokens=4096, messages=messages, **config
|
||||
)
|
||||
)
|
||||
result = _convert(
|
||||
AnthropicCountTokensRequest(model="test-model", messages=messages, **config)
|
||||
)
|
||||
assert result.reasoning_effort == expected.reasoning_effort
|
||||
assert result.thinking_token_budget == expected.thinking_token_budget
|
||||
|
||||
|
||||
class TestProbeDisabledThinkingEffort:
|
||||
"""``auto`` falls back to ``low`` when ``none`` cannot turn thinking off."""
|
||||
|
||||
Reference in New Issue
Block a user