erictik / midjourney-api

MidJourney client. Unofficial Node.js client
Apache License 2.0
1.71k stars 287 forks source link

Please pass the seed as a parameter. #127

Open sukbearai opened 1 year ago

sukbearai commented 1 year ago
 async Imagine(prompt: string, loading?: LoadingHandler,customSeed:number) {
    prompt = prompt.trim();
    if (!this.wsClient) {
      const seed = CustomSeed ?? random(1000000000, 9999999999);
      prompt = `[${seed}] ${prompt}`;
    }

    const nonce = nextNonce();
    this.log(`Imagine`, prompt, "nonce", nonce);
    const httpStatus = await this.MJApi.ImagineApi(prompt, nonce);
    if (httpStatus !== 204) {
      throw new Error(`ImagineApi failed with status ${httpStatus}`);
    }
    if (this.wsClient) {
      return await this.wsClient.waitImageMessage(nonce, loading);
    } else {
      this.log(`await generate image`);
      const msg = await this.WaitMessage(prompt, loading);
      this.log(`image generated`, prompt, msg?.uri);
      return msg;
    }
  }

// The following two functions also need to add a timestamp 🙏🙏
WaitUpscaledMessage(content: string,index: number,loading?: LoadingHandler,timestamp: number)
WaitOptionMessage(content: string,options: string,loading?: LoadingHandler,timestamp: number)
zcpua commented 1 year ago

WaitUpscaledMessage & WaitOptionMessage deprecated

zcpua commented 1 year ago

recommend using Ws:true,huggingface:"token",

Ws:false may be baned.

sukbearai commented 1 year ago

I also want to use ws, but I can't use it, because my SCF persistent connection will have problems, so I can only split it to poll WaitMessage through the client

sukbearai commented 1 year ago

I’ll fork a copy and make some adjustments.