Skip to content

Make it easier to get the final output only #37

Closed
@evilstreak

Description

@evilstreak

To get just the final output from a model that produces progressive output requires something like this:

import replicate
model = replicate.model(“kuprel/min-dalle”)
output = list(model.predict(“a black swan”))[-1]

That’s a bit of a handful, but the bigger issue is that it’s really not obvious.

You can’t call [-1] on the iterator because it’s not a list, so Python doesn’t know how to index from the end. Knowing you have to convert it to a list first seems non-obvious to Python newcomers, which some of our users will be.

Worse than that though, IMO, is that you have to know that the model generates progressive output. You need different code depending on whether or not the mode produces an iterator, and it’s not easy to find that information. Even if we made it easier I think it’d be clearer to explicitly state whether you want intermediate outputs or not, and to give you either an iterator or a single output accordingly.

If you want a single output from a model with an iterator, the library could just throw away the other results. If you want an iterator from a model that has none, the library could wrap it for you. That way the author is saying how they want to consume it, rather than adjusting their code to the model.

This’ll also help when models change between versions, either adding or removing progressive output, as previously working code won’t break with errors.

Data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions