replicate / replicate-javascript

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

prediction failing in the code but finishing in the browser #88

Closed AlexStan0 closed 1 year ago

AlexStan0 commented 1 year ago

When I create a prediciton with the code below it returns an erorr in the CLI but the prediciton goes through in the dashboard without isses

Code:

async generate(prompt, negativePrompt, width, height) {

        //make sure that the height and the width fit in the specified restricitons
        if(!(height <= 1024 && width <= 768) || !(width <= 1024 && height <= 768)) throw new Error("please enter a resolution below the maximum resolution of 768x1024");

        //store the location for what model to create a prediction from
        const modelLocation = `${this.#username}/${this.#model}:${this.#modelVersion}`;

        //store the input options for the creation call
        const inputOptions = {
            prompt: prompt,
            negative_prompt: negativePrompt,
            width: width,
            height: height
        }

        //call the model and generate 
        const output = await this.#replicate.run(
            modelLocation,
            {
                input: inputOptions
            }
        );

        //create an object with the image info
        const imageInfo = {
            imageLink: output[0],
            prompt: prompt,
            negativePrompt: negativePrompt,
            height: height,
            width: width
        }

        return imageInfo

    } //end generate()

EDIT: Forgot to add, this is the error I'm getting

FetchError: request to https://api.replicate.com/v1/predictions/wqljaprbzn5q4aiqh6ooy3wieu failed, reason: 
    at ClientRequest.<anonymous> (file:///home/alexa/forknife-v5/node_modules/node-fetch/src/index.js:108:11)
    at ClientRequest.emit (node:events:511:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:511:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ENETUNREACH',
  code: 'ENETUNREACH',
  erroredSysCall: undefined
mattt commented 1 year ago

Hi @AlexStan0. Sorry, I don't have the context to understand exactly what the problem is here. It looks like your code is failing at the transport layer, in node-fetch, so I'm not sure if there's anything to be done in the SDK or API. Could it be that this.#replicate is getting cleaned up, and closing its connection in the process?

mattt commented 1 year ago

@AlexStan0 Let me know if you're still having trouble getting this to work. Thanks!