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
This commit is contained in:
committed by
Copybara-Service
parent
ecbefd9547
commit
065234e279
@@ -1329,7 +1329,7 @@ async def _get_content(
|
||||
)
|
||||
content_objects.append({
|
||||
"type": "file",
|
||||
"file": {"file_id": file_response.id},
|
||||
"file": {"file_id": file_response.id, "format": mime_type},
|
||||
})
|
||||
else:
|
||||
content_objects.append({
|
||||
|
||||
@@ -5104,6 +5104,7 @@ async def test_get_content_pdf_openai_uses_file_id(mocker):
|
||||
|
||||
assert content[0]["type"] == "file"
|
||||
assert content[0]["file"]["file_id"] == "file-abc123"
|
||||
assert content[0]["file"]["format"] == "application/pdf"
|
||||
assert "file_data" not in content[0]["file"]
|
||||
|
||||
mock_acreate_file.assert_called_once_with(
|
||||
@@ -5144,6 +5145,7 @@ async def test_get_content_pdf_azure_uses_file_id(mocker):
|
||||
|
||||
assert content[0]["type"] == "file"
|
||||
assert content[0]["file"]["file_id"] == "file-xyz789"
|
||||
assert content[0]["file"]["format"] == "application/pdf"
|
||||
|
||||
mock_acreate_file.assert_called_once_with(
|
||||
file=b"test_pdf_data",
|
||||
@@ -5189,6 +5191,7 @@ async def test_get_completion_inputs_openai_file_upload(mocker):
|
||||
assert content[0]["text"] == "Analyze this PDF"
|
||||
assert content[1]["type"] == "file"
|
||||
assert content[1]["file"]["file_id"] == "file-uploaded123"
|
||||
assert content[1]["file"]["format"] == "application/pdf"
|
||||
|
||||
mock_acreate_file.assert_called_once()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user