core/agent: unify provider finish_reason mapping

This commit is contained in:
2026-08-01 01:05:26 +08:00
parent 5198a8da20
commit 626012e92f
4 changed files with 73 additions and 14 deletions
+32
View File
@@ -0,0 +1,32 @@
"""Tests for the canonical finish_reason vocabulary shared by provider bridges."""
from __future__ import annotations
import pytest
from plyngent.agent.finish_reason import chat_finish_reason
@pytest.mark.parametrize(
("raw", "has_tool_calls", "expected"),
[
(None, False, "stop"),
(None, True, "tool_calls"),
("", False, "stop"),
("end_turn", False, "stop"),
("stop_sequence", False, "stop"),
("completed", False, "stop"),
("stop", False, "stop"),
("max_tokens", False, "length"),
("max_output_tokens", False, "length"),
("length", False, "length"),
("content_filter", False, "content_filter"),
("refusal", False, "content_filter"),
("tool_use", False, "tool_calls"),
("tool_calls", False, "tool_calls"),
("Tool_Use", False, "tool_calls"),
("MAX_TOKENS", False, "length"),
],
)
def test_chat_finish_reason(raw: str | None, has_tool_calls: bool, expected: str) -> None:
assert chat_finish_reason(raw, has_tool_calls=has_tool_calls) == expected