From 586ab1b07276c767d06a5517f0c1e346ee26cdca Mon Sep 17 00:00:00 2001 From: Will Sackfield Date: Tue, 5 Aug 2025 12:19:58 -0400 Subject: [PATCH 1/3] Log prediction URLs with env var gate * Log prediction URLs from the replicate python SDK if the environment variable R8_LOG_PREDICTION_URL is set to 1 --- replicate/use.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/replicate/use.py b/replicate/use.py index 596674e..3d6f4a1 100644 --- a/replicate/use.py +++ b/replicate/use.py @@ -3,6 +3,7 @@ # - [ ] Support file streaming import copy import hashlib +import logging import os import tempfile from functools import cached_property @@ -210,6 +211,12 @@ def _resolve_ref(obj: Any) -> Any: return result +def _log_prediction_url(id: str) -> None: + if os.environ.get("R8_LOG_PREDICTION_URL") != "1": + return + logging.info("Running prediction https://replicate.com/p/%s", id) + + T = TypeVar("T") @@ -436,6 +443,8 @@ def create(self, *_: Input.args, **inputs: Input.kwargs) -> Run[Output]: model=self._model, input=processed_inputs ) + _log_prediction_url(prediction.id) + return Run( prediction=prediction, schema=self.openapi_schema(), @@ -649,6 +658,8 @@ async def create(self, *_: Input.args, **inputs: Input.kwargs) -> AsyncRun[Outpu model=model, input=processed_inputs ) + _log_prediction_url(prediction.id) + return AsyncRun( prediction=prediction, schema=await self.openapi_schema(), From bf6edd78b81a3aa40ef9e51a6329c3706caff54f Mon Sep 17 00:00:00 2001 From: Will Sackfield Date: Tue, 5 Aug 2025 13:00:10 -0400 Subject: [PATCH 2/3] Use print instead of logging --- replicate/use.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/replicate/use.py b/replicate/use.py index 3d6f4a1..7a3db29 100644 --- a/replicate/use.py +++ b/replicate/use.py @@ -3,7 +3,6 @@ # - [ ] Support file streaming import copy import hashlib -import logging import os import tempfile from functools import cached_property @@ -214,7 +213,7 @@ def _resolve_ref(obj: Any) -> Any: def _log_prediction_url(id: str) -> None: if os.environ.get("R8_LOG_PREDICTION_URL") != "1": return - logging.info("Running prediction https://replicate.com/p/%s", id) + print("Running prediction https://replicate.com/p/%s", id) T = TypeVar("T") From ec32bea266675c79a69554b21af16c99d4649a61 Mon Sep 17 00:00:00 2001 From: Will Sackfield Date: Tue, 5 Aug 2025 14:38:52 -0400 Subject: [PATCH 3/3] Fix %s call --- replicate/use.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replicate/use.py b/replicate/use.py index 7a3db29..28d94c6 100644 --- a/replicate/use.py +++ b/replicate/use.py @@ -213,7 +213,7 @@ def _resolve_ref(obj: Any) -> Any: def _log_prediction_url(id: str) -> None: if os.environ.get("R8_LOG_PREDICTION_URL") != "1": return - print("Running prediction https://replicate.com/p/%s", id) + print(f"Running prediction https://replicate.com/p/{id}") T = TypeVar("T")