Skip to content

fix: recurse through nested JSON file inputs#3036

Open
immanuwell wants to merge 1 commit into
replicate:mainfrom
immanuwell:fix/nested-json-path-inputs
Open

fix: recurse through nested JSON file inputs#3036
immanuwell wants to merge 1 commit into
replicate:mainfrom
immanuwell:fix/nested-json-path-inputs

Conversation

@immanuwell
Copy link
Copy Markdown
Contributor

cog predict --json only rewrites top level @file values rn. If those paths sit inside arrays or nested objects, they go through as raw @... strings, so list[Path] style inputs via JSON are kinda busted.

This makes the rewrite recursive for JSON arrays and objects. Added a unit test and an integration test too.

Repro:
cog build -t $TEST_IMAGE
cog predict $TEST_IMAGE --json '{"paths": ["@1.txt", "@2.txt"]}'

Before this, the CLI sends literal @1.txt strings and the prediction falls over.
After this, those entries become data URLs and it works.

Related: #1344

@immanuwell immanuwell requested a review from a team as a code owner May 30, 2026 08:54
Comment thread pkg/cli/predict.go
if mimeType == "" {
mimeType = "application/octet-stream"
}
func transformJSONValuePathsToBase64URLs(value any) (any, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you didnt introduce this, and its called out in the docs that @ is reserved for file paths, but Im thinking in the future we should somehow make this more resilient or atleast make the error message better , since this will fail if a user tries to pass in @string thats not a file path. like:

{"metadata":{"handle":"@alice"}} or {"tags":["@foo"]}

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.

2 participants