e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
124 lines
3.5 KiB
Python
124 lines
3.5 KiB
Python
"""Reasoning-content handling for OpenAI-compatible providers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from deeptutor.services.llm.provider_core.openai_compat_provider import (
|
|
OpenAICompatProvider as ServicesOpenAICompatProvider,
|
|
)
|
|
from deeptutor.services.provider_registry import find_by_name as find_service_provider
|
|
|
|
|
|
def _response_with_reasoning_only():
|
|
message = SimpleNamespace(
|
|
content=None,
|
|
reasoning_content="internal reasoning",
|
|
reasoning=None,
|
|
tool_calls=None,
|
|
)
|
|
return SimpleNamespace(
|
|
choices=[SimpleNamespace(message=message, finish_reason="stop")],
|
|
)
|
|
|
|
|
|
def _reasoning_only_chunk():
|
|
delta = SimpleNamespace(
|
|
content=None,
|
|
reasoning_content="internal reasoning",
|
|
reasoning=None,
|
|
tool_calls=[],
|
|
)
|
|
return SimpleNamespace(
|
|
choices=[SimpleNamespace(delta=delta, finish_reason="stop")],
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"provider_cls",
|
|
[ServicesOpenAICompatProvider],
|
|
)
|
|
def test_parse_keeps_reasoning_content_out_of_visible_content(provider_cls) -> None:
|
|
provider = provider_cls.__new__(provider_cls)
|
|
|
|
response = provider._parse(_response_with_reasoning_only())
|
|
|
|
assert response.content is None
|
|
assert response.reasoning_content == "internal reasoning"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"provider_cls",
|
|
[ServicesOpenAICompatProvider],
|
|
)
|
|
def test_parse_chunks_keeps_reasoning_content_out_of_visible_content(provider_cls) -> None:
|
|
response = provider_cls._parse_chunks([_reasoning_only_chunk()])
|
|
|
|
assert response.content is None
|
|
assert response.reasoning_content == "internal reasoning"
|
|
|
|
|
|
def _build_services_kwargs(
|
|
provider_name: str,
|
|
reasoning_effort: str | None,
|
|
*,
|
|
model: str = "deepseek-v4-pro",
|
|
) -> dict:
|
|
provider = ServicesOpenAICompatProvider.__new__(ServicesOpenAICompatProvider)
|
|
provider.default_model = model
|
|
provider._spec = find_service_provider(provider_name)
|
|
return provider._build_kwargs(
|
|
messages=[{"role": "user", "content": "hello"}],
|
|
tools=None,
|
|
model=None,
|
|
max_tokens=32,
|
|
temperature=0.7,
|
|
reasoning_effort=reasoning_effort,
|
|
tool_choice=None,
|
|
)
|
|
|
|
|
|
def test_services_provider_minimal_reasoning_uses_extra_body_only() -> None:
|
|
kwargs = _build_services_kwargs("deepseek", "minimal")
|
|
|
|
assert "reasoning_effort" not in kwargs
|
|
assert kwargs["extra_body"] == {"thinking": {"type": "disabled"}}
|
|
|
|
|
|
def test_services_deepseek_v4_flash_disables_thinking_by_default() -> None:
|
|
kwargs = _build_services_kwargs(
|
|
"deepseek",
|
|
None,
|
|
model="deepseek-v4-flash",
|
|
)
|
|
|
|
assert "reasoning_effort" not in kwargs
|
|
assert kwargs["extra_body"] == {"thinking": {"type": "disabled"}}
|
|
|
|
|
|
def test_services_deepseek_v4_pro_enables_thinking_by_default() -> None:
|
|
kwargs = _build_services_kwargs("deepseek", None)
|
|
|
|
assert kwargs["reasoning_effort"] == "high"
|
|
assert kwargs["extra_body"] == {"thinking": {"type": "enabled"}}
|
|
|
|
|
|
def test_services_dashscope_minimal_reasoning_uses_enable_thinking_only() -> None:
|
|
kwargs = _build_services_kwargs("dashscope", "minimal")
|
|
|
|
assert "reasoning_effort" not in kwargs
|
|
assert kwargs["extra_body"] == {"enable_thinking": False}
|
|
|
|
|
|
def test_services_custom_qwen_enables_thinking_without_top_level_effort() -> None:
|
|
kwargs = _build_services_kwargs(
|
|
"custom",
|
|
None,
|
|
model="qwen3.6-plus",
|
|
)
|
|
|
|
assert "reasoning_effort" not in kwargs
|
|
assert kwargs["extra_body"] == {"enable_thinking": True}
|