Skip to content

Commit 586ab1b

Browse files
committed
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
1 parent 974dd7f commit 586ab1b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

replicate/use.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# - [ ] Support file streaming
44
import copy
55
import hashlib
6+
import logging
67
import os
78
import tempfile
89
from functools import cached_property
@@ -210,6 +211,12 @@ def _resolve_ref(obj: Any) -> Any:
210211
return result
211212

212213

214+
def _log_prediction_url(id: str) -> None:
215+
if os.environ.get("R8_LOG_PREDICTION_URL") != "1":
216+
return
217+
logging.info("Running prediction https://replicate.com/p/%s", id)
218+
219+
213220
T = TypeVar("T")
214221

215222

@@ -436,6 +443,8 @@ def create(self, *_: Input.args, **inputs: Input.kwargs) -> Run[Output]:
436443
model=self._model, input=processed_inputs
437444
)
438445

446+
_log_prediction_url(prediction.id)
447+
439448
return Run(
440449
prediction=prediction,
441450
schema=self.openapi_schema(),
@@ -649,6 +658,8 @@ async def create(self, *_: Input.args, **inputs: Input.kwargs) -> AsyncRun[Outpu
649658
model=model, input=processed_inputs
650659
)
651660

661+
_log_prediction_url(prediction.id)
662+
652663
return AsyncRun(
653664
prediction=prediction,
654665
schema=await self.openapi_schema(),

0 commit comments

Comments
 (0)