* * a simple example of how to use the vary * ``` * npx tsx example/vary.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 custom zoom |
| 17 | }); |
| 18 | await client.init(); |
| 19 | const prompt = |
| 20 | "Christmas dinner with spaghetti with family in a cozy house, we see interior details , simple blue&white illustration"; |
| 21 | const Imagine = await client.Imagine( |
| 22 | prompt, |
| 23 | (uri: string, progress: string) => { |
| 24 | console.log("loading", uri, "progress", progress); |
| 25 | } |
| 26 | ); |
| 27 | console.log(Imagine); |
| 28 | if (!Imagine) { |
| 29 | console.log("no message"); |
| 30 | return; |
| 31 | } |
| 32 | const Upscale = await client.Upscale({ |
| 33 | index: 2, |
| 34 | msgId: <string>Imagine.id, |
| 35 | hash: <string>Imagine.hash, |
| 36 | flags: Imagine.flags, |
| 37 | loading: (uri: string, progress: string) => { |
| 38 | console.log("loading", uri, "progress", progress); |
| 39 | }, |
| 40 | }); |
| 41 | if (!Upscale) { |
| 42 | console.log("no message"); |
| 43 | return; |
| 44 | } |
| 45 | console.log(Upscale); |
| 46 | |
| 47 | const vary = Upscale?.options?.find((o) => o.label === "Vary (Strong)"); |
| 48 | if (!vary) { |
| 49 | console.log("no zoomout"); |
| 50 | return; |
| 51 | } |
| 52 | const varyCustom = await client.Custom({ |
| 53 | msgId: <string>Upscale.id, |
| 54 | flags: Upscale.flags, |
| 55 | content: `${prompt} --zoom 2`, |
| 56 | customId: vary.custom, |
| 57 | loading: (uri: string, progress: string) => { |
| 58 | console.log("loading", uri, "progress", progress); |
| 59 | }, |
| 60 | }); |
| 61 | console.log("vary (Strong)", varyCustom); |
| 62 | client.Close(); |
| 63 | } |
| 64 | main() |
| 65 | .then(() => { |
| 66 | console.log("done"); |