-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from erictik/ws-wait-message
👋 Important update
- Loading branch information
Showing
19 changed files
with
853 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import "dotenv/config"; | ||
import { Midjourney } from "../src"; | ||
/** | ||
* | ||
* a simple example of how to use the imagine command | ||
* ``` | ||
* npx tsx example/imagine-err.ts | ||
* ``` | ||
*/ | ||
async function main() { | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
Debug: true, | ||
SessionId: process.env.SALAI_TOKEN || "8bb7f5b79c7a49f7d0824ab4b8773a81", | ||
}); | ||
|
||
await client.init(); | ||
const msg = await client.Imagine( | ||
"A little white elephant --ar1:1", | ||
(uri: string, progress: string) => { | ||
console.log("loading", uri, "progress", progress); | ||
} | ||
); | ||
console.log({ msg }); | ||
} | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import "dotenv/config"; | ||
import { Midjourney } from "../src"; | ||
/** | ||
* | ||
* a simple example of using the imagine api with ws | ||
* ``` | ||
* npx tsx example/imagine-ws.ts | ||
* ``` | ||
*/ | ||
async function main() { | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
Debug: true, | ||
Ws: true, | ||
}); | ||
await client.init(); | ||
const msg = await client.Imagine( | ||
"A little white dog", | ||
(uri: string, progress: string) => { | ||
console.log("loading", uri, "progress", progress); | ||
} | ||
); | ||
console.log({ msg }); | ||
} | ||
main() | ||
.then(() => { | ||
console.log("finished"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.log("finished"); | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import "dotenv/config"; | ||
import { Midjourney } from "../src"; | ||
/** | ||
* | ||
* a simple example of how to use the Upscale with ws command | ||
* ``` | ||
* npx tsx example/upscale-ws.ts | ||
* ``` | ||
*/ | ||
async function main() { | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
Debug: true, | ||
Ws: true, | ||
}); | ||
await client.init(); | ||
const msg = await client.Imagine("a cool cat, blue ears, yellow hat"); | ||
console.log({ msg }); | ||
if (!msg) { | ||
console.log("no message"); | ||
return; | ||
} | ||
const msg2 = await client.Upscale( | ||
msg.content, | ||
2, | ||
<string>msg.id, | ||
<string>msg.hash, | ||
(uri: string, progress: string) => { | ||
console.log("loading", uri, "progress", progress); | ||
} | ||
); | ||
console.log({ msg2 }); | ||
} | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import "dotenv/config"; | ||
import { Midjourney } from "../src"; | ||
/** | ||
* | ||
* a simple example of how to use the Variation with ws command | ||
* ``` | ||
* npx tsx example/variation-ws.ts | ||
* ``` | ||
*/ | ||
async function main() { | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
Debug: true, | ||
Ws: true, | ||
}); | ||
await client.init(); | ||
const msg = await client.Imagine("a dog, blue ears, and a red nose"); | ||
console.log({ msg }); | ||
if (!msg) { | ||
console.log("no message"); | ||
return; | ||
} | ||
const msg2 = await client.Variation( | ||
msg.content, | ||
2, | ||
<string>msg.id, | ||
<string>msg.hash, | ||
(uri: string) => { | ||
console.log("loading", uri); | ||
} | ||
); | ||
console.log({ msg2 }); | ||
} | ||
main().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./midjourney"; | ||
export * from "./midjourney.message"; | ||
export * from "./ws.message"; | ||
export * from "./interfaces/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./message"; | ||
export * from "./message.config"; | ||
export * from "./config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
export interface Message { | ||
text: string; | ||
img: string; | ||
} | ||
|
||
export interface MJMessage { | ||
id: string; | ||
uri: string; | ||
hash: string; | ||
content: string; | ||
id?: string; | ||
hash?: string; | ||
progress?: string; | ||
} | ||
|
||
export type LoadingHandler = (uri: string, progress: string) => void; | ||
|
||
export interface WaitMjEvent { | ||
type: "imagine" | "upscale" | "variation" | "info"; | ||
nonce: string; | ||
prompt?: string; | ||
id?: string; | ||
index?: number; | ||
} | ||
export interface WsEventMsg { | ||
error?: Error; | ||
message?: MJMessage; | ||
} | ||
export type ImageEventType = "imagine" | "upscale" | "variation"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.