MCPcopy
hub / github.com/erictik/midjourney-api / Imagine

Method Imagine

src/midjourney.ts:57–80  ·  view source on GitHub ↗
(prompt: string, loading?: LoadingHandler)

Source from the content-addressed store, hash-verified

55 return this;
56 }
57 async Imagine(prompt: string, loading?: LoadingHandler) {
58 prompt = prompt.trim();
59 if (!this.config.Ws) {
60 const seed = random(1000000000, 9999999999);
61 prompt = `[${seed}] ${prompt}`;
62 } else {
63 await this.getWsClient();
64 }
65
66 const nonce = nextNonce();
67 this.log(`Imagine`, prompt, "nonce", nonce);
68 const httpStatus = await this.MJApi.ImagineApi(prompt, nonce);
69 if (httpStatus !== 204) {
70 throw new Error(`ImagineApi failed with status ${httpStatus}`);
71 }
72 if (this.wsClient) {
73 return await this.wsClient.waitImageMessage({ nonce, loading, prompt });
74 } else {
75 this.log(`await generate image`);
76 const msg = await this.WaitMessage(prompt, loading);
77 this.log(`image generated`, prompt, msg?.uri);
78 return msg;
79 }
80 }
81 // check ws enabled && connect
82 private async getWsClient() {
83 if (!this.config.Ws) {

Callers 15

mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 7

getWsClientMethod · 0.95
randomFunction · 0.90
nextNonceFunction · 0.90
ImagineApiMethod · 0.80
waitImageMessageMethod · 0.80
WaitMessageMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected