This commit is contained in:
@@ -163,14 +163,15 @@ def _flatten_any_llm_reasoning_value(value: Any) -> str:
|
||||
if flattened:
|
||||
return flattened
|
||||
return ""
|
||||
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
|
||||
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
|
||||
return "".join(part for part in parts if part)
|
||||
|
||||
for attr in ("content", "text", "thinking"):
|
||||
flattened = _flatten_any_llm_reasoning_value(getattr(value, attr, None))
|
||||
if flattened:
|
||||
return flattened
|
||||
|
||||
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
|
||||
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
|
||||
return "".join(part for part in parts if part)
|
||||
return ""
|
||||
|
||||
|
||||
@@ -829,6 +830,7 @@ class AnyLLMModel(Model):
|
||||
handoffs=handoffs,
|
||||
model=self._provider_model,
|
||||
)
|
||||
|
||||
converted_tools = OpenAIResponsesConverter.convert_tools(
|
||||
tools,
|
||||
handoffs,
|
||||
|
||||
@@ -739,3 +739,17 @@ def test_any_llm_provider_passes_api_override() -> None:
|
||||
|
||||
assert isinstance(model, AnyLLMModel)
|
||||
assert model.api == "chat_completions"
|
||||
|
||||
|
||||
def test_any_llm_reasoning_objects_prefer_content_attributes_over_iterable_pairs() -> None:
|
||||
pytest.importorskip(
|
||||
"any_llm",
|
||||
reason="`any-llm-sdk` is only available when the optional dependency is installed.",
|
||||
)
|
||||
from any_llm.types.completion import Reasoning
|
||||
|
||||
from agents.extensions.models.any_llm_model import _extract_any_llm_reasoning_text
|
||||
|
||||
delta = pytypes.SimpleNamespace(reasoning=Reasoning(content="用户"))
|
||||
|
||||
assert _extract_any_llm_reasoning_text(delta) == "用户"
|
||||
|
||||
Reference in New Issue
Block a user