This commit is contained in:
li2631026381-alt 2026-09-13 00:02:08 -07:00 • committed by GitHub
commit d16738d9d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 61 additions and 2 deletions

View file

@ -970,7 +970,13 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
if role in ("user", "system", "developer", "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
@ -1078,7 +1084,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,