@@ -608,6 +608,65 @@ async def test_use_iterator_of_paths_output(use_async_client):
608608 assert output_list [1 ].read_bytes () == b"fake image 2 data"
609609
610610
611+ @pytest .mark .asyncio
612+ @pytest .mark .parametrize ("use_async_client" , [False ])
613+ @respx .mock
614+ async def test_use_pathproxy_input_conversion (use_async_client ):
615+ """Test that PathProxy instances are converted to URLs when passed to create()."""
616+ mock_model_endpoints ()
617+
618+ # Mock the file download - this should NOT be called
619+ file_request_mock = respx .get ("https://example.com/input.jpg" ).mock (
620+ return_value = httpx .Response (200 , content = b"fake input image data" )
621+ )
622+
623+ # Create a PathProxy instance
624+ from replicate .use import PathProxy
625+
626+ path_proxy = PathProxy ("https://example.com/input.jpg" )
627+
628+ # Set up a mock for the prediction creation to capture the request
629+ request_body = None
630+
631+ def capture_request (request ):
632+ nonlocal request_body
633+ request_body = request .read ()
634+ return httpx .Response (
635+ 201 ,
636+ json = {
637+ "id" : "pred789" ,
638+ "model" : "acme/hotdog-detector" ,
639+ "version" : "xyz123" ,
640+ "urls" : {
641+ "get" : "https://api.replicate.com/v1/predictions/pred789" ,
642+ "cancel" : "https://api.replicate.com/v1/predictions/pred789/cancel" ,
643+ },
644+ "created_at" : "2024-01-01T00:00:00Z" ,
645+ "source" : "api" ,
646+ "status" : "processing" ,
647+ "input" : {"image" : "https://example.com/input.jpg" },
648+ "output" : None ,
649+ "error" : None ,
650+ "logs" : "" ,
651+ },
652+ )
653+
654+ respx .post ("https://api.replicate.com/v1/predictions" ).mock (
655+ side_effect = capture_request
656+ )
657+
658+ # Call use and create with PathProxy
659+ hotdog_detector = replicate .use ("acme/hotdog-detector" )
660+ run = hotdog_detector .create (image = path_proxy )
661+
662+ # Verify the request body contains the URL, not the downloaded file
663+ parsed_body = json .loads (request_body )
664+ assert parsed_body ["input" ]["image" ] == "https://example.com/input.jpg"
665+
666+ # Assert that the file was never downloaded
667+ assert file_request_mock .call_count == 0
668+
669+
611670@pytest .mark .asyncio
612671@pytest .mark .parametrize ("use_async_client" , [False ])
613672@respx .mock
0 commit comments