41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from langchain_core.messages import AIMessage, AIMessageChunk
|
|
|
|
from deerflow.models.patched_openai import (
|
|
_append_reasoning_content,
|
|
_extract_reasoning_content,
|
|
_restore_reasoning_content,
|
|
)
|
|
|
|
|
|
def test_extracts_legacy_reasoning_content():
|
|
assert _extract_reasoning_content({"reasoning_content": "legacy"}) == "legacy"
|
|
|
|
|
|
def test_extracts_vllm_reasoning():
|
|
assert _extract_reasoning_content({"reasoning": "new spelling"}) == "new spelling"
|
|
|
|
|
|
def test_normalizes_vllm_reasoning_for_existing_clients():
|
|
message = AIMessageChunk(content="")
|
|
|
|
updated = _append_reasoning_content(message, "thinking", reasoning="thinking")
|
|
|
|
assert updated.additional_kwargs["reasoning_content"] == "thinking"
|
|
assert updated.additional_kwargs["reasoning"] == "thinking"
|
|
|
|
|
|
def test_restores_original_vllm_reasoning_spelling_for_follow_up_turn():
|
|
original = AIMessage(
|
|
content="answer",
|
|
additional_kwargs={
|
|
"reasoning": "thinking",
|
|
"reasoning_content": "thinking",
|
|
},
|
|
)
|
|
payload = {"role": "assistant", "content": "answer"}
|
|
|
|
_restore_reasoning_content(payload, original)
|
|
|
|
assert payload["reasoning"] == "thinking"
|
|
assert "reasoning_content" not in payload
|