erictik / midjourney-api Goto Github PK
View Code? Open in Web Editor NEWMidJourney client. Unofficial Node.js client
License: Apache License 2.0
MidJourney client. Unofficial Node.js client
License: Apache License 2.0
Hey, and thank you for uploading this,
I have two suggestions for improvement that I noticed while using it.
Thus, a possibility is needed to write several messages with the same text.
I would be happy if there is an option to run concurrent jobs as well as named jobs.
Tank you :)
hi Erictik,
This is Weijiang, I really wanna give a BIG THANK YOU to your work! it help me a lot to ship the MJ feature.
Btw, some ideas:
Thanks,
thank you for amazing work, I've study the code few days ago , theres remix api in the Midjourney class , but deleted in later commit , is there any way to support this function ?
hi, nice script. but when yarn install still get stuck esbuild. and please add other command like info,describe
Error: ImagineApi failed with status 400
at Midjourney.Imagine (d:\work\project\test\midjourney-api\src\midjourney.ts:46:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at main (d:\work\project\test\midjourney-api\example\imagine-ws.ts:20:15)
I love your Project!
A little Correction for the readme:
"
Then, run the example with the following command:
npx tsx example/imagine-ws.ts
npx tsx example/upscale-w.ts
"
should be :
"
Then, run the example with the following command:
npx tsx example/imagine-ws.ts
npx tsx example/upscale-ws.ts
"
Have a great day.
The program fails in Docker container when submitting the prompt from the UI:
(base) morpher@rog ~/Documents/MyProjects/midjourney-ui (main)$ docker run --env-file .env -p 3000:3000 erictik/midjourney-ui
yarn run v1.22.19
$ next start
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
imagine.handler unicorn
imagine.start unicorn
ReadableStream class {
constructor(e2 = {}, t2 = {}) {
void 0 === e2 ? e2 = null : D(e2, "First parameter");
const r2 = Ye(t2, "Second parameter"), o2 = function(e3, t3) {
F(e3, t3);
const r3 = e3, o3 = null == r3 ? void 0 : r3.autoAllocateChunkSize, n3 = null == r3 ? void 0 : r3.cancel, a2 = null == r3 ? void 0 : r3.pull, i2 = null == r3 ? void 0 : r3.start, l2 = null == r3 ? void 0 : r3.type;
return { autoAllocateChunkSize: void 0 === o3 ? void 0 : N(o3, `${t3} has member 'autoAllocateChunkSize' that`), cancel: void 0 === n3 ? void 0 : $t(n3, r3, `${t3} has member 'cancel' that`), pull: void 0 === a2 ? void 0 : Mt(a2, r3, `${t3} has member 'pull' that`), start: void 0 === i2 ? void 0 : Yt(i2, r3, `${t3} has member 'start' that`), type: void 0 === l2 ? void 0 : Qt(l2, `${t3} has member 'type' that`) };
}(e2, "First parameter");
var n2;
if ((n2 = this)._state = "readable", n2._reader = void 0, n2._storedError = void 0, n2._disturbed = false, "bytes" === o2.type) {
if (void 0 !== r2.size)
throw new RangeError("The strategy for a byte stream cannot have a size function");
Oe(this, o2, $e(r2, 0));
} else {
const e3 = Me(r2);
It(this, o2, $e(r2, 1), e3);
}
}
get locked() {
if (!Vt(this))
throw Kt("locked");
return Ut(this);
}
cancel(e2) {
return Vt(this) ? Ut(this) ? d(new TypeError("Cannot cancel a stream that already has a reader")) : Gt(this, e2) : d(Kt("cancel"));
}
getReader(e2) {
if (!Vt(this))
throw Kt("getReader");
return void 0 === function(e3, t2) {
F(e3, t2);
const r2 = null == e3 ? void 0 : e3.mode;
return { mode: void 0 === r2 ? void 0 : Nt(r2, `${t2} has member 'mode' that`) };
}(e2, "First parameter").mode ? new ReadableStreamDefaultReader(this) : function(e3) {
return new ReadableStreamBYOBReader(e3);
}(this);
}
pipeThrough(e2, t2 = {}) {
if (!H(this))
throw Kt("pipeThrough");
$(e2, 1, "pipeThrough");
const r2 = xt(e2, "First parameter"), o2 = Ht(t2, "Second parameter");
if (this.locked)
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");
if (r2.writable.locked)
throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");
return m(kt(this, r2.writable, o2.preventClose, o2.preventAbort, o2.preventCancel, o2.signal)), r2.readable;
}
pipeTo(e2, t2 = {}) {
if (!H(this))
return d(Kt("pipeTo"));
if (void 0 === e2)
return d("Parameter 1 is required in 'pipeTo'.");
if (!x(e2))
return d(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));
let r2;
try {
r2 = Ht(t2, "Second parameter");
} catch (e3) {
return d(e3);
}
return this.locked ? d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")) : e2.locked ? d(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")) : kt(this, e2, r2.preventClose, r2.preventAbort, r2.preventCancel, r2.signal);
}
tee() {
if (!H(this))
throw Kt("tee");
if (this.locked)
throw new TypeError("Cannot tee a stream that already has a reader");
return Ot(this);
}
values(e2) {
if (!H(this))
throw Kt("values");
return function(e3, t2) {
const r2 = e3.getReader(), o2 = new te(r2, t2), n2 = Object.create(re);
return n2._asyncIteratorImpl = o2, n2;
}(this, function(e3, t2) {
F(e3, t2);
const r2 = null == e3 ? void 0 : e3.preventCancel;
return { preventCancel: Boolean(r2) };
}(e2, "First parameter").preventCancel);
}
}
imagine.error [Error: A Node.js API is used (setImmediate) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime]
Any request in dev mode fires this error
Running on Ubuntu 20:
`error - node:child_process
Module build failed: UnhandledSchemeError: Reading from "node:child_process" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:child_process
./node_modules/discord.js/src/sharding/Shard.js
./node_modules/discord.js/src/index.js
./node_modules/midjourney/libs/midjourney.js
./node_modules/midjourney/libs/index.js
wait - compiling /_error (client and server)...
warn - ./node_modules/discord.js/src/client/websocket/WebSocketManager.js
Module not found: Can't resolve 'zlib-sync' in '/home/anton/_npm_projects/midjourney-ui/node_modules/discord.js/src/client/websocket'
Import trace for requested module:
./node_modules/discord.js/src/client/websocket/WebSocketManager.js
./node_modules/discord.js/src/index.js
./node_modules/midjourney/libs/midjourney.js
./node_modules/midjourney/libs/index.js
`
Running on Windows 10:
`
Trying to build also failed. Please assist
Error: ImagineApi failed with status 400
at Midjourney.Imagine (/Users/username/github/midjourney-api/src/midjourney.ts:24:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at main (/Users/username/github/midjourney-api/example/imagine.ts:17:15)
if (data.length >= 4 && data.readUInt32BE(data.length - 4) === 0x0ffff) {
this.inflate.flush(
ZlibConstants.Z_SYNC_FLUSH,
this.handleFlushComplete.bind(this),
)
}
Sometimes an error occurs when executing the above statement
Uncaught Exception thrown Error: invalid stored block lengths
at Zlib.zlibOnError [as onerror] (node:zlib:189:17) {
errno: -3,
code: 'Z_DATA_ERROR'
}
Upscale no msg return. when the Upscale img has been created, but the msg2 not return, still repect waitting
cmd: npx tsx example/upscale.ts
is midjourney paid subscription needed to use?
Hey Eric !
First Thanks for your amazing work, it works great on my side :)
Are you planning to have a solution to be able to select one of the 4 options, then retreive the uri ?
Or even to make variation/refresh just like on discord :)
Have a great day
Sometimes midjourney response with prompt - @user (Open on website for full quality) (fast)
as the final message when the image is ready.
In such cases, the Imagine API is returning no response. Can a timeout be configured at least so that I don't wait endlessly?
check if upscaled imagine already exist
Hi, I have quite a problem to make this work. Could you please help me a little bit?
Error: Cannot find module '../libs'
Hi!
inside src/midjourney.ts I need to change the async Upscale method using a return as follow:
return await this.WaitOptionMessage(content, 'Image #' + index, loading)
I discovered that inside my channel on Discord after my request prompt, midjourney bot put a "Image #" text followed by the index of image choosen in upscale request.
I hope this is useful.
Regards,
Roberto
Error: ImagineApi failed with status 400
at Midjourney.Imagine (/Users/jinhu/Development/ChatAI/midjourney-api/src/midjourney.ts:23:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at main (/Users/jinhu/Development/ChatAI/midjourney-api/example/upscale.ts:17:15)
(base) ➜ midjourney-api git:(main) ✗
Can I call back the incorrect card information when the prompt word is wrong or not conforming to the specification? Thanks
I tried the example you provided but I got this error
ReferenceError: fetch is not defined
at Midjourney.<anonymous> (D:\Projects\...\midjourney\node_modules\midjourney\libs\midjourney.js:49:34)
Running upscale.ts and not working. return "msg: undefined"
我想要让 midjourney 按照图片生成图片。
[202]:~/midjourney-api(main)$ ./init.sh MidjourneyMessage constructor 2023-05-12T09:35:17.751Z
Imagine https://i0.hdslb.com/bfs/vc/bc954b9250303d69f601b534424be6dc54c58ce8.png a cat --seed 2221 2023-05-12T09:35:17.752Z
await generate image 2023-05-12T09:35:18.372Z
0 wait no message found 2023-05-12T09:35:18.815Z
1 wait no message found 2023-05-12T09:35:21.326Z
2 wait no message found 2023-05-12T09:35:23.732Z
3 wait no message found 2023-05-12T09:35:26.107Z
4 wait no message found 2023-05-12T09:35:28.574Z
5 wait no message found 2023-05-12T09:35:30.984Z
6 wait no message found 2023-05-12T09:35:33.360Z
7 wait no message found 2023-05-12T09:35:35.738Z
8 wait no message found 2023-05-12T09:35:38.112Z
Image variation works fine for the last image, but there are issues when variation the images before, and will get wrong images.
thank you very much
请问后面会出账号池轮询功能吗,一个账号会不够用 同时作业太少了
It would be nice to increase the delay for the returned {msg}, sometimes Midjourney can take time to start the generation, and msg is returned undefined before the generation ended.
I'm thinking about doing it manually meanwhile, can you help me by giving me the line of code (if possible) my knowledge are limited ?
Thank you
why report Error: ImagineApi failed with status 500
async function main() {
const client = new Midjourney({
...config,
})
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,
msg.id,
msg.hash,
(uri) => {
console.log('loading', uri)
},
)
console.log({ msg2 })
}
main()
and then it return the result like:
{
msg: {
id: '1111517800503201842',
uri: 'https://cdn.discordapp.com/attachments/1107512663669493833/1111517799899205662/RuthDavis_a_dog_blue_ears_and_a_red_nose_5192b71e-a948-477e-a87b-99ed7bd9857c.png',
hash: '5192b71e-a948-477e-a87b-99ed7bd9857c',
content: 'a dog, blue ears, and a red nose --seed 7856 --v 5',
progress: 'done'
}
}
{ msg2: null }
Hey again,
thx for ur great work !
I've noticed that if you variate a generation twice, seems like the code cannot make the difference between the first variation and the second one, so it takes the first one instead of waiting for the second one.
Looks like it is over time
const MaxWait = 600
const Limit = 100
export default async function (ctx: FunctionContext) {
const { msg_id, imaginePrompt, serverId, channelId, salaiToken } = ctx.body
const client = new Midjourney({
ServerId: serverId,
ChannelId: channelId,
SalaiToken: salaiToken,
Debug: true,
MaxWait: MaxWait,
SessionId: salaiToken,
Limit: Limit,
});
const msg = await client.Imagine("A little pink elephant ", (uri) => {
console.log("loading", uri);
});
return { msg }
}
Some examples of http status 401
latest version, send error like this :
Error: ImagineApi failed with status 401
at Midjourney. (/main/server/node_modules/midjourney/libs/midjourney.js:26:23)
The message always return NULL when i used this prompt to the client.Imagine
Prompt: "A dragon, a Chinese little girl in ancient attire,The dragon and the little girl are intimate, elegant, realistic, and have many details".
please have a look, 100% reproduced.
I can run 'node ./example/imagine.js but can't run 'npx tsx ./example/imagine.ts' with the following error
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/xxx/Projects/js-project/midjourney-api/main.ts' imported from /Users/xxx/Projects/js-project/midjourney-api/
at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
at new NodeError (node:internal/errors:399:5)
at finalizeResolution (node:internal/modules/esm/resolve:231:11)
at moduleResolve (node:internal/modules/esm/resolve:850:10)
at defaultResolve (node:internal/modules/esm/resolve:1058:11)
at nextResolve (node:internal/modules/esm/loader:163:28)
at u (file:///Users/panjianbo/Projects/js-project/midjourney-api/node_modules/@esbuild-kit/esm-loader/dist/index.js:1:2406)
at nextResolve (node:internal/modules/esm/loader:163:28)
at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:416:18)
at ESMLoader.import (node:internal/modules/esm/loader:517:22)
at node:internal/modules/run_main:56:28
at loadESM (node:internal/process/esm_loader:94:11)
at async handleMainPromise (node:internal/modules/run_main:66:12) {
code: 'ERR_MODULE_NOT_FOUND'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.