@@ -2139,3 +2139,50 @@ async def __aexit__(self, *args):
21392139 # Verify the final speech_config is still None
21402140 assert config_arg .speech_config is None
21412141 assert isinstance (connection , GeminiLlmConnection )
2142+
2143+
2144+ @pytest .mark .asyncio
2145+ async def test_preprocess_request_unsupported_mime_type (gemini_llm ):
2146+ """Verifies that MS Office files are escaped to a text reference."""
2147+ unsupported_part = types .Part (
2148+ file_data = types .FileData (
2149+ mime_type = "application/vnd.ms-excel" ,
2150+ file_uri = "gs://bucket/data.xls" ,
2151+ display_name = "data.xls"
2152+ )
2153+ )
2154+ req = LlmRequest (
2155+ model = "gemini-2.0-flash" ,
2156+ contents = [types .Content (parts = [unsupported_part ])]
2157+ )
2158+
2159+ await gemini_llm ._preprocess_request (req )
2160+
2161+ processed_part = req .contents [0 ].parts [0 ]
2162+ # File_data should be stripped to avoid the 400 error
2163+ assert processed_part .file_data is None
2164+ # Text fallback should be present
2165+ assert '[File reference: "data.xls"]' in processed_part .text
2166+
2167+
2168+ @pytest .mark .asyncio
2169+ async def test_preprocess_request_supported_mime_type (gemini_llm ):
2170+ """Verifies that PDF files are passed through without modification."""
2171+ supported_part = types .Part (
2172+ file_data = types .FileData (
2173+ mime_type = "application/pdf" ,
2174+ file_uri = "gs://bucket/doc.pdf" ,
2175+ display_name = "doc.pdf"
2176+ )
2177+ )
2178+ req = LlmRequest (
2179+ model = "gemini-2.0-flash" ,
2180+ contents = [types .Content (parts = [supported_part ])]
2181+ )
2182+
2183+ await gemini_llm ._preprocess_request (req )
2184+
2185+ processed_part = req .contents [0 ].parts [0 ]
2186+ # file_data should still be intact
2187+ assert processed_part .file_data is not None
2188+ assert processed_part .file_data .mime_type == "application/pdf"
0 commit comments