* * a simple example of using the imagine api with ws * ``` * npx tsx example/imagine-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 | HuggingFaceToken: <string>process.env.HUGGINGFACE_TOKEN, |
| 16 | Debug: true, |
| 17 | Ws: true, // required `Only you can see this` |
| 18 | }); |
| 19 | await client.Connect(); // required |
| 20 | const Imagine = await client.Imagine( |
| 21 | "Red hamster smoking a cigaret --fast", |
| 22 | (uri: string, progress: string) => { |
| 23 | console.log("Imagine.loading", uri, "progress", progress); |
| 24 | } |
| 25 | ); |
| 26 | console.log({ Imagine }); |
| 27 | if (!Imagine) { |
| 28 | return; |
| 29 | } |
| 30 | const reroll = await client.Reroll({ |
| 31 | msgId: <string>Imagine.id, |
| 32 | hash: <string>Imagine.hash, |
| 33 | flags: Imagine.flags, |
| 34 | loading: (uri: string, progress: string) => { |
| 35 | console.log("Reroll.loading", uri, "progress", progress); |
| 36 | }, |
| 37 | }); |
| 38 | console.log({ reroll }); |
| 39 | |
| 40 | const Variation = await client.Variation({ |
| 41 | index: 2, |
| 42 | msgId: <string>Imagine.id, |
| 43 | hash: <string>Imagine.hash, |
| 44 | flags: Imagine.flags, |
| 45 | loading: (uri: string, progress: string) => { |
| 46 | console.log("Variation.loading", uri, "progress", progress); |
| 47 | }, |
| 48 | }); |
| 49 | |
| 50 | console.log({ Variation }); |
| 51 | if (!Variation) { |
| 52 | return; |
| 53 | } |
| 54 | const Upscale = await client.Upscale({ |
| 55 | index: 2, |
| 56 | msgId: <string>Variation.id, |
| 57 | hash: <string>Variation.hash, |
| 58 | flags: Variation.flags, |
| 59 | loading: (uri: string, progress: string) => { |
| 60 | console.log("Upscale.loading", uri, "progress", progress); |
| 61 | }, |
| 62 | }); |
| 63 | console.log({ Upscale }); |
| 64 | |
| 65 | client.Close(); |
| 66 | } |
| 67 | main() |