From 2c997d993ac86bad3ac13b44d1449ac1efe323e6 Mon Sep 17 00:00:00 2001 From: xswl Date: Wed, 19 Jul 2023 22:08:39 +0800 Subject: [PATCH] fix --- README.md | 74 ++++++++++++++++++++++++++++++++----------- README_zh.md | 74 ++++++++++++++++++++++++++++++++----------- example/customzoom.ts | 38 ++++++++++++++++------ example/vary.ts | 2 -- 4 files changed, 141 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 9495b0e..1ebfefb 100644 --- a/README.md +++ b/README.md @@ -124,37 +124,75 @@ To run the included example, you must have [Node.js](https://nodejs.org/en/) ins ChannelId: process.env.CHANNEL_ID, SalaiToken: process.env.SALAI_TOKEN, Debug: true, - Ws: true, + Ws: true, //enable ws is required for remix mode (and custom zoom) }); - await client.Connect(); + await client.init(); + const prompt = + "Christmas dinner with spaghetti with family in a cozy house, we see interior details , simple blue&white illustration"; + //imagine const Imagine = await client.Imagine( - "A little pink elephant", + prompt, (uri: string, progress: string) => { - console.log("Imagine", uri, "progress", progress); + console.log("loading", uri, "progress", progress); } ); - console.log({ Imagine }); - - const Variation = await client.Variation({ - index: 2, + console.log(Imagine); + if (!Imagine) { + console.log("no message"); + return; + } + //U1 U2 U3 U4 V1 V2 V3 V4 "Vary (Strong)" ... + const V1CustomID = Imagine.options?.find((o) => o.label === "V1")?.custom; + if (!V1CustomID) { + console.log("no V1"); + return; + } + // Varition V1 + const Varition = await client.Custom({ + msgId: Imagine.id, + flags: Imagine.flags, + customId: V1CustomID, + content: prompt, //remix mode require content + loading: (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); + }, + }); + console.log(Varition); + const U1CustomID = Imagine.options?.find((o) => o.label === "U1")?.custom; + if (!U1CustomID) { + console.log("no U1"); + return; + } + // Upscale U1 + const Upscale = await client.Custom({ msgId: Imagine.id, - hash: Imagine.hash, flags: Imagine.flags, + customId: U1CustomID, loading: (uri: string, progress: string) => { - console.log("Variation.loading", uri, "progress", progress); + console.log("loading", uri, "progress", progress); }, }); - console.log({ Variation }); - const Upscale = await client.Upscale({ - index: 2, - msgId: Variation.id, - hash: Variation.hash, - flags: Variation.flags, + if (!Upscale) { + console.log("no Upscale"); + return; + } + console.log(Upscale); + const zoomout = Upscale?.options?.find((o) => o.label === "Custom Zoom"); + if (!zoomout) { + console.log("no zoomout"); + return; + } + // Custom Zoom + const CustomZoomout = await client.Custom({ + msgId: Upscale.id, + flags: Upscale.flags, + content: `${prompt} --zoom 2`, // Custom Zoom require content + customId: zoomout.custom, loading: (uri: string, progress: string) => { - console.log("Upscale.loading", uri, "progress", progress); + console.log("loading", uri, "progress", progress); }, }); - console.log({ Upscale }); + console.log(CustomZoomout); ``` ## route-map diff --git a/README_zh.md b/README_zh.md index 710472d..1d65e7c 100644 --- a/README_zh.md +++ b/README_zh.md @@ -125,37 +125,75 @@ ChannelId: process.env.CHANNEL_ID, SalaiToken: process.env.SALAI_TOKEN, Debug: true, - Ws: true, + Ws: true, //enable ws is required for remix mode (and custom zoom) }); - await client.Connect(); + await client.init(); + const prompt = + "Christmas dinner with spaghetti with family in a cozy house, we see interior details , simple blue&white illustration"; + //imagine const Imagine = await client.Imagine( - "A little pink elephant", + prompt, (uri: string, progress: string) => { - console.log("Imagine", uri, "progress", progress); + console.log("loading", uri, "progress", progress); } ); - console.log({ Imagine }); - - const Variation = await client.Variation({ - index: 2, + console.log(Imagine); + if (!Imagine) { + console.log("no message"); + return; + } + // U1 U2 U3 U4 V1 V2 V3 V4 "Vary (Strong)" ... + const V1CustomID = Imagine.options?.find((o) => o.label === "V1")?.custom; + if (!V1CustomID) { + console.log("no V1"); + return; + } + // Varition V1 + const Varition = await client.Custom({ + msgId: Imagine.id, + flags: Imagine.flags, + customId: V1CustomID, + content: prompt, //remix mode require content + loading: (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); + }, + }); + console.log(Varition); + const U1CustomID = Imagine.options?.find((o) => o.label === "U1")?.custom; + if (!U1CustomID) { + console.log("no U1"); + return; + } + // Upscale U1 + const Upscale = await client.Custom({ msgId: Imagine.id, - hash: Imagine.hash, flags: Imagine.flags, + customId: U1CustomID, loading: (uri: string, progress: string) => { - console.log("Variation.loading", uri, "progress", progress); + console.log("loading", uri, "progress", progress); }, }); - console.log({ Variation }); - const Upscale = await client.Upscale({ - index: 2, - msgId: Variation.id, - hash: Variation.hash, - flags: Variation.flags, + if (!Upscale) { + console.log("no Upscale"); + return; + } + console.log(Upscale); + const zoomout = Upscale?.options?.find((o) => o.label === "Custom Zoom"); + if (!zoomout) { + console.log("no zoomout"); + return; + } + // Custom Zoom + const CustomZoomout = await client.Custom({ + msgId: Upscale.id, + flags: Upscale.flags, + content: `${prompt} --zoom 2`, // Custom Zoom require content + customId: zoomout.custom, loading: (uri: string, progress: string) => { - console.log("Upscale.loading", uri, "progress", progress); + console.log("loading", uri, "progress", progress); }, }); - console.log({ Upscale }); + console.log(CustomZoomout); ``` ## route-map diff --git a/example/customzoom.ts b/example/customzoom.ts index 4d85174..615599b 100644 --- a/example/customzoom.ts +++ b/example/customzoom.ts @@ -1,6 +1,5 @@ import "dotenv/config"; import { Midjourney } from "../src"; -import { sleep } from "../src/utls"; /** * * a simple example of how to use the (custom zoom) options with ws command @@ -19,6 +18,7 @@ async function main() { await client.init(); const prompt = "Christmas dinner with spaghetti with family in a cozy house, we see interior details , simple blue&white illustration"; + //imagine const Imagine = await client.Imagine( prompt, (uri: string, progress: string) => { @@ -30,28 +30,48 @@ async function main() { console.log("no message"); return; } - const Upscale = await client.Upscale({ - index: 2, + //U1 U2 U3 U4 V1 V2 V3 V4 "Vary (Strong)" ... + const V1CustomID = Imagine.options?.find((o) => o.label === "V1")?.custom; + if (!V1CustomID) { + console.log("no V1"); + return; + } + // Varition V1 + const Varition = await client.Custom({ msgId: Imagine.id, - hash: Imagine.hash, flags: Imagine.flags, + customId: V1CustomID, + loading: (uri: string, progress: string) => { + console.log("loading", uri, "progress", progress); + }, + }); + console.log(Varition); + const U1CustomID = Imagine.options?.find((o) => o.label === "U1")?.custom; + if (!U1CustomID) { + console.log("no U1"); + return; + } + // Upscale U1 + const Upscale = await client.Custom({ + msgId: Imagine.id, + flags: Imagine.flags, + customId: U1CustomID, loading: (uri: string, progress: string) => { console.log("loading", uri, "progress", progress); }, }); if (!Upscale) { - console.log("no message"); + console.log("no Upscale"); return; } console.log(Upscale); - const zoomout = Upscale?.options?.find((o) => o.label === "Custom Zoom"); if (!zoomout) { console.log("no zoomout"); return; } - await sleep(1400); - const zoomout2x = await client.Custom({ + // Custom Zoom + const CustomZoomout = await client.Custom({ msgId: Upscale.id, flags: Upscale.flags, content: `${prompt} --zoom 2`, @@ -60,7 +80,7 @@ async function main() { console.log("loading", uri, "progress", progress); }, }); - console.log("Custom Zoom", zoomout2x); + console.log("Custom Zoom", CustomZoomout); client.Close(); } main() diff --git a/example/vary.ts b/example/vary.ts index 93f5213..bbc385e 100644 --- a/example/vary.ts +++ b/example/vary.ts @@ -1,6 +1,5 @@ import "dotenv/config"; import { Midjourney } from "../src"; -import { sleep } from "../src/utls"; /** * * a simple example of how to use the vary @@ -50,7 +49,6 @@ async function main() { console.log("no zoomout"); return; } - await sleep(1400); const varyCustom = await client.Custom({ msgId: Upscale.id, flags: Upscale.flags,