Added pagination for predictions.list + a new predictions.list_before_date function#108
Closed
andreemic wants to merge 2 commits intoreplicate:mainfrom
Closed
Added pagination for predictions.list + a new predictions.list_before_date function#108andreemic wants to merge 2 commits intoreplicate:mainfrom
andreemic wants to merge 2 commits intoreplicate:mainfrom
Conversation
Signed-off-by: mikhailandreev <andreemic@gmail.com>
Signed-off-by: mikhailandreev <andreemic@gmail.com>
|
I wanted to use this but i was getting some parsing errors. like to get it going i had to set |
Contributor
|
Hi @andreemic. Thank you for opening this PR. Sorry for not responding sooner. I just merged #189, which is now available in version 0.17.0. Currently, Replicate's API doesn't provide a way to specify a date range for predictions (though that's something I'd like to add). Fetching all predictions before a given date will have the effect of fetching all of you predictions and discarding all of the leading entries before you reach that target date, so I wouldn't recommend doing this unless absolutely necessary. Using the new from datetime import datetime
import replicate
predictions = []
page = replicate.predictions.list()
target_date = datetime.strptime('2023-01-01', '%Y-%m-%d')
while page:
predictions.extend(page.results)
if page.next and predictions and datetime.strptime(predictions[-1].created_at, '%Y-%m-%dT%H:%M:%S.%fZ') > target_date:
page = replicate.predictions.list(page.next)
else:
break
# Filter predictions to only include those created before or at the target date
predictions = [p for p in predictions if datetime.strptime(p.created_at, '%Y-%m-%dT%H:%M:%S.%fZ') <= target_date] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We (https://www.virtualstagingai.app) use replicate for production inference and wanted to keep an overview over our costs.
Since the Replicate dashboard is very simplistic, I added two functions here which we routinely use to aggregate and analyze inference data, to understand where our costs come from.
The changes are pretty simple and backwards-compatible, let me know if you have questions or change requests.
Thanks for Replicate!