Skip to content

Commit 065234e

Browse files
GWealecopybara-github
authored andcommitted
fix: preserve non-image file MIME type in LiteLlm content conversion
When converting an inlined artifact Part to a LiteLlm/OpenAI file block, the MIME type of non-image files was dropped and sent as None, so OpenAI rejected PDFs loaded via load_artifacts (while Gemini and Claude worked). Propagate the part's mime_type into the file content block. Close #4174 Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 949061584
1 parent ecbefd9 commit 065234e

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/google/adk/models/lite_llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ async def _get_content(
13291329
)
13301330
content_objects.append({
13311331
"type": "file",
1332-
"file": {"file_id": file_response.id},
1332+
"file": {"file_id": file_response.id, "format": mime_type},
13331333
})
13341334
else:
13351335
content_objects.append({

tests/unittests/models/test_litellm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,6 +5104,7 @@ async def test_get_content_pdf_openai_uses_file_id(mocker):
51045104

51055105
assert content[0]["type"] == "file"
51065106
assert content[0]["file"]["file_id"] == "file-abc123"
5107+
assert content[0]["file"]["format"] == "application/pdf"
51075108
assert "file_data" not in content[0]["file"]
51085109

51095110
mock_acreate_file.assert_called_once_with(
@@ -5144,6 +5145,7 @@ async def test_get_content_pdf_azure_uses_file_id(mocker):
51445145

51455146
assert content[0]["type"] == "file"
51465147
assert content[0]["file"]["file_id"] == "file-xyz789"
5148+
assert content[0]["file"]["format"] == "application/pdf"
51475149

51485150
mock_acreate_file.assert_called_once_with(
51495151
file=b"test_pdf_data",
@@ -5189,6 +5191,7 @@ async def test_get_completion_inputs_openai_file_upload(mocker):
51895191
assert content[0]["text"] == "Analyze this PDF"
51905192
assert content[1]["type"] == "file"
51915193
assert content[1]["file"]["file_id"] == "file-uploaded123"
5194+
assert content[1]["file"]["format"] == "application/pdf"
51925195

51935196
mock_acreate_file.assert_called_once()
51945197

0 commit comments

Comments
 (0)