* * a simple example of how to use the Variation (remix mode) with ws command * ``` * npx tsx example/variation-ws.ts * ```
()
| 8 | * ``` |
| 9 | */ |
| 10 | async function main() { |
| 11 | const client = new Midjourney({ |
| 12 | ServerId: <string>process.env.SERVER_ID, |
| 13 | ChannelId: <string>process.env.CHANNEL_ID, |
| 14 | SalaiToken: <string>process.env.SALAI_TOKEN, |
| 15 | Debug: true, |
| 16 | Ws: true, //enable ws is required for remix mode |
| 17 | }); |
| 18 | await client.init(); //init auto enable remix mode |
| 19 | const prompt = |
| 20 | "48 year old woman with auburn hair plays video games on a tablet in her bedroom and is a chemist. Engaged. Happy. Evening. Silver blue walls in room. In the style of anime. does not exceed 10 MB."; |
| 21 | const Imagine = await client.Imagine( |
| 22 | prompt, |
| 23 | (uri: string, progress: string) => { |
| 24 | console.log("Imagine.loading", uri, "progress", progress); |
| 25 | } |
| 26 | ); |
| 27 | console.log(Imagine); |
| 28 | if (!Imagine) { |
| 29 | console.log("no message"); |
| 30 | return; |
| 31 | } |
| 32 | const Variation = await client.Variation({ |
| 33 | index: 1, |
| 34 | msgId: <string>Imagine.id, |
| 35 | hash: <string>Imagine.hash, |
| 36 | flags: Imagine.flags, |
| 37 | content: prompt, |
| 38 | loading: (uri: string, progress: string) => { |
| 39 | console.log("Variation1.loading", uri, "progress", progress); |
| 40 | }, |
| 41 | }); |
| 42 | console.log("Variation", Variation); |
| 43 | if (!Variation) { |
| 44 | console.log("no Variation"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | const Upscale = await client.Upscale({ |
| 49 | index: 2, |
| 50 | msgId: <string>Variation.id, |
| 51 | hash: <string>Variation.hash, |
| 52 | flags: Variation.flags, |
| 53 | content: prompt, |
| 54 | loading: (uri: string, progress: string) => { |
| 55 | console.log("Upscale.loading", uri, "progress", progress); |
| 56 | }, |
| 57 | }); |
| 58 | console.log("Upscale", Upscale); |
| 59 | // client |
| 60 | // .Variation({ |
| 61 | // index: 2, |
| 62 | // msgId: <string>Imagine.id, |
| 63 | // hash: <string>Imagine.hash, |
| 64 | // flags: Imagine.flags, |
| 65 | // loading: (uri: string, progress: string) => { |
| 66 | // console.log("Variation2.loading", uri, "progress", progress); |
| 67 | // }, |