diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 9deb3fd0ab6..746745cc791 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -883,10 +883,10 @@ _CHARSET_AWARE_MEDIA_TYPE: Final = "text/plain" def _media_type_with_original_parameters(format_override: str, original_media_type: str) -> str: - if format_override.strip() != _CHARSET_AWARE_MEDIA_TYPE: + if format_override.strip().lower() != _CHARSET_AWARE_MEDIA_TYPE: return format_override base_type, separator, parameters = original_media_type.partition(";") - if not separator or base_type.strip() != format_override.strip(): + if not separator or base_type.strip().lower() != format_override.strip().lower(): return format_override return f"{format_override}{separator}{parameters}" diff --git a/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py index 4179dafe570..9cb574bada5 100644 --- a/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py +++ b/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py @@ -5235,8 +5235,20 @@ _LATIN1_TEXT_DATA_URI = "data:text/plain;charset=iso-8859-1;base64," + base64.b6 {"type": "image_url", "image_url": {"url": "data:TEXT/PLAIN;base64," + _TEXT_B64}}, "the secret code word is MANGO\n", ), + ( + {"type": "image_url", "image_url": {"url": _LATIN1_TEXT_DATA_URI.replace("text/plain", "TEXT/PLAIN", 1)}}, + "the secret code word is MANGĂ“\n", + ), + ], + ids=[ + "image_url", + "file", + "image_url_charset", + "file_charset", + "file_latin1", + "image_url_uppercase", + "uppercase_latin1", ], - ids=["image_url", "file", "image_url_charset", "file_charset", "file_latin1", "image_url_uppercase"], ) def test_anthropic_messages_pt_text_plain_data_uri_becomes_text_source_document(block, expected_text): messages = [{"role": "user", "content": [{"type": "text", "text": "What is the code word?"}, block]}]