erictik / midjourney-api

MidJourney client. Unofficial Node.js client
Apache License 2.0
1.69k stars 283 forks source link

[suggestion] multiple connections #277

Open GabrieleRisso opened 3 months ago

GabrieleRisso commented 3 months ago

Hello, thanks for the exellent api. I am using every feature of the api (version 5.2) and face swap consistently without issues. In my codebase I am running multiple istances of the same program using cluster workers and I have the feeling some of those istances are having toruble to conenct, resulting in a failure. I was wandering if you could suggest a better way of implementing the connection setup or config parameters to tune it in order to have 16 parallel connections. here is my current implementation:

import { ImIDnfigParam, Midjourney } from "midjourney";

const ImIDnfig: ImIDnfigParam = { SalaiToken: process.env.SALAI_TOKEN, ChannelId: process.env.CHANNEL_ID, ServerId: process.env.SERVER_ID, HuggingFaceToken: "hf_XXXXXXXXXXXXXXXXXXXXXX", //Debug: true, Ws: true, //Limit: 200 };

const midclient = new Midjourney(ImIDnfig);

await midclient .init() .then(() => { console.log("[OK] MidClient initialized successfully."); }) .catch((error) => { console.error("[XX] Failed to initialize MidClient:", error); });

const msg = await midclient .Imagine(${prompt} --quality ${quality}, (uri: string, progress: string) => { console.log("Imagine.loading", uri, "progress", progress); }) .catch((error) => { console.error("Error in midclient.Imagine:", error); throw error; // Rethrow the error to propagate it further });