This commit is contained in:
li2631026381-alt 2026-08-26 21:54:02 +02:00 committed by GitHub
commit 47fac4b652
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 2 deletions

View file

@ -922,7 +922,13 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
if role == "user" or role == "system" or role == "tool":
return {"type": "input_text", "text": content}
else:
return {"type": "output_text", "text": content}
return {"type": "output_text", "text": content, "annotations": []}
@staticmethod
def _ensure_output_text_annotations(item: dict[str, object]) -> dict[str, object]:
if item.get("type") == "output_text":
return {"annotations": [], **item}
return item
def _convert_content_to_responses_format_image(
self, content: "ChatCompletionImageObject", role: str
@ -1027,7 +1033,7 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
"summary_text",
]:
# Already in responses API format
result.append(item)
result.append(self._ensure_output_text_annotations(item))
verbose_logger.debug("Chat provider: passthrough -> %s", item)
else:
# Default to input_text for unknown types

View file

@ -21,6 +21,59 @@ if TYPE_CHECKING:
from litellm.types.utils import ModelResponse
@pytest.mark.parametrize(
("content", "expected_content"),
[
(
"ok",
[{"type": "output_text", "text": "ok", "annotations": []}],
),
(
[{"type": "text", "text": "ok"}],
[{"type": "output_text", "text": "ok", "annotations": []}],
),
(
[{"type": "input_text", "text": "ok"}],
[{"type": "input_text", "text": "ok"}],
),
(
[{"type": "output_text", "text": "ok"}],
[{"type": "output_text", "text": "ok", "annotations": []}],
),
(
[
{
"type": "output_text",
"text": "ok",
"annotations": [{"type": "url_citation", "url": "https://example.com"}],
}
],
[
{
"type": "output_text",
"text": "ok",
"annotations": [{"type": "url_citation", "url": "https://example.com"}],
}
],
),
],
)
def test_assistant_output_text_includes_required_annotations(content, expected_content):
handler = LiteLLMResponsesTransformationHandler()
response, _ = handler.convert_chat_completion_messages_to_responses_api(
[{"role": "assistant", "content": content}]
)
assert response == [
{
"type": "message",
"role": "assistant",
"content": expected_content,
}
]
def test_convert_chat_completion_messages_to_responses_api_image_input():
from litellm.completion_extras.litellm_responses_transformation.transformation import (
LiteLLMResponsesTransformationHandler,