replicate / replicate-javascript

Node.js client for Replicate
https://replicate.com/docs/get-started/nodejs
Apache License 2.0
473 stars 193 forks source link

`RangeError: Maximum call stack size exceeded` for image buffer input #247

Closed zeke closed 4 months ago

zeke commented 5 months ago

I've got this code:

import Replicate from 'replicate'

const replicate = new Replicate()

const model = 'yorickvp/llava-v1.6-34b:41ecfbfb261e6c1adf3ad896c9066ca98346996d7c4045c5bc944a79d430f174'

export default async function describeImage (imageBuffer) {
  const input = {
    image: imageBuffer,
    prompt: "What's happening in this image?"
  }
  const output = await replicate.run(model, { input })
  return output
}

And this image:

IMG_1700

I'm trying to feed this image to https://replicate.com/yorickvp/llava-v1.6-34b as a buffer:

const buffer = await readFile(imagePath)
console.log({ buffer })
{
  buffer: <Buffer ff d8 ff e1 01 08 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 12 00 03 00 00 00 01 00 01 00 00 01 1a 00 05 00 00 00 01 00 00 00 56 01 1b 00 05 ... 401476 more bytes>
}

But I'm getting this error:

Error processing images: RangeError: Maximum call stack size exceeded
    at bytesToBase64 (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:136:35)
    at /Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:245:18
    at transform (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:272:16)
    at transform (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:267:25)
    at transformFileInputs (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/util.js:219:24)
    at Replicate.createPrediction (/Users/z/Desktop/los-angeles/node_modules/replicate/lib/predictions.js:33:22)
    at Replicate.run (/Users/z/Desktop/los-angeles/node_modules/replicate/index.js:138:43)
    at describeImage (file:///Users/z/Desktop/los-angeles/describe-image.js:14:34)
aron commented 5 months ago

@zeke what platform are you running this on? NodeJS?

I think the solution here is to merge #184 and utilize the file upload endpoint, I hadn't realized it hasn't been merged yet. @mattt what are your thoughts?

mattt commented 4 months ago

@aron Yeah, I think the Files API would be the best solution to this. Let's chat about what's blocking us from shipping that.

zeke commented 4 months ago

I hadn't realized it hasn't been merged yet.

Ah yeah same.. I was thinking, "Isn't this file supposed to be uploaded automatically by the client now?" That explains it.

Files API sounds good to me. 👍🏼

armenavanesi commented 4 months ago

Hey any updates on when this fix will be merged? I'm following the upload guide that can be accessed from any model and neither File, Blob, and Buffer uploads all give me this error. Thanks

EvansUchwa commented 4 months ago

Hey any updates on when this fix will be merged? I'm following the upload guide that can be accessed from any model and neither File, Blob, and Buffer uploads all give me this error. Thanks

Hello, I also have the same problem. Were you able to find a solution?

zeke commented 4 months ago

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror
EvansUchwa commented 4 months ago

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror

Thanks a lot ,you saved my life🙏🏿

geronimi73 commented 4 months ago

We're going to ship #184, but in the short term you can temporarily work around it by npm installing this branch from GitHub:

npm install replicate/replicate-javascript#fix-rangeerror

Thanks a lot ,you saved my life🙏🏿

mine too. please ship this PR

zeke commented 4 months ago

@mattt just landed v0.30.0 with support for automatically uploading your file inputs and turning them into URL inputs to your predictions. That should solve this issue!

To use it:

npm install replicate@latest