-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support run tokens #2105
base: main
Are you sure you want to change the base?
Support run tokens #2105
Conversation
"Run tokens" are used to run downstream Replicate models from within a model. They are not yet exposed in an API, but can be found inside a Cog predictor with some ugly frame inspection: ```python def _find_api_token() -> str: frame = inspect.currentframe() while frame: if "self" in frame.f_locals: self = frame.f_locals["self"] if hasattr(self, "_current_run_token"): token = self._current_run_token return token frame = frame.f_back raise ValueError("No run token found in call stack") ```
This makes run_token available via current_scope. Example usage: ```python from cog import current_scope class MyPredictor: def predict(self): token = current_scope().run_token() if token: # use token ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a commit to expose run_token via current_scope, which we added as a way to expose per-prediction functionality like this.
Eventually this should just be a value.
3cb68d5
to
b06a692
Compare
python/cog/include.py
Outdated
|
||
def include(model_path: str) -> Callable[..., Any]: | ||
def run(**inputs: dict[str, Any]) -> Any: | ||
client = replicate.Client(api_token=_find_api_token()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can use current_scope().run_token
, which is the affordance that exposes the run token to the model. In future, if the prototype is successful, we should make replicate-python automatically detect this and use it if no token was explicitly provided.
Further, I think the whole include
function here probably belongs on replicate-python, not in cog?
"Run tokens" are used to run downstream Replicate models from within a model.
They are not yet exposed in an API, but can be found inside a Cog predictor with some ugly frame inspection: