Skip to content

Conversation

@aron
Copy link
Contributor

@aron aron commented Nov 24, 2025

Currently we only convert URLPath instances into URL strings if passed directly as an input parameter. We want to ensure that we convert all instances of URLPaths provided otherwise we get JSON encoding errors.

The most common use of this is passing a list of files that were output from another model. Here is a minimal reproduction:

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "replicate>=2b3",
# ]
# ///

import replicate
from replicate.lib._predictions_use import URLPath

video_stitcher = replicate.use("andreasjansson/video-stitcher")


def main() -> None:
    output = video_stitcher(
        videos=[
            URLPath(
                "https://replicate.delivery/xezq/ueemmhGfowaxnp2zx4rQAwZWkIGMkeoEFGwDMB8FJDDUPGiTB/tmpsam6b5v3.mp4"
            ),
            URLPath(
                "https://replicate.delivery/xezq/yitkxodvCK7eJK9BFufsMBaHIfnHgJhlNNIiaQi8g8QebGiTB/tmpby0sgn7w.mp4"
            ),
        ]
    )
    print("output", output)


if __name__ == "__main__":
    main()

This can be run with:

uv run main.py
> TypeError: Object of type URLPath is not JSON serializable

This PR attempts to transform the most common Python data structures into either lists or dicts and in doing so extracts the underlying URL value from any URL path instances.

Note

This might be better implemented as a custom JSON encoder.

aron added 2 commits November 24, 2025 15:19
This fixes an issue where the instance rather than the class was passed
into use resulting in an exception when performing the `isinstance`
check in `use()`.
Currently we only convert `URLPath` instances into URL strings if passed
directly as an input parameter. We want to ensure that we convert all
instances of `URLPath`s provided otherwise we get JSON encoding errors.

The most common use of this is passing a list of files that were output
from another model.

This PR attempts to transform the most common Python data structures
into either lists or dicts and in doing so extracts the underlying URL
value from any `URL` path instances.

This might be better implemented as a custom JSON encoder.
@aron aron changed the title transform inputs Improve transformation of inputs passed to Function.create() Nov 24, 2025
@aron aron marked this pull request as ready for review November 24, 2025 15:26
@aron aron requested a review from a team as a code owner November 24, 2025 15:26
@ms-jpq

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants