Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pan-right, works with remix prompt #201

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch example:pan",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"example:pan"
],
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal", // this will run the script in the integrated terminal
"internalConsoleOptions": "neverOpen" // prevents the debug console from taking focus
}
]
}
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
HOW TO USE A CUSTOM PACKAGE

Compile the TypeScript Code:

Based on the package.json you've shared, there is a build script that uses the TypeScript Compiler (tsc). This will compile the .ts files from the src directory to .js files in the libs directory.

In the root directory of the midjourney project, run:

bash
Copy code
npm run build
Package and Install in Your Own Project:

If your main project is located in a different directory, you can package the improved midjourney module and install it in your project.

Navigate to the midjourney directory and run:

bash
Copy code
npm pack
This will create a .tgz file, for instance, midjourney-4.0.0.tgz.

Then, in your main project directory, install the .tgz file:

bash
Copy code
npm install path_to_tgz_file/midjourney-4.0.0.tgz

# midjourney-client

Node.js client for the unofficial MidJourney api.
Expand All @@ -16,6 +44,7 @@ English / [中文文档](README_zh.md)
- [face swap](https://github.com/erictik/midjourney-client/blob/main/example/faceswap.ts)
- [niji bot](https://github.com/erictik/midjourney-client/blob/main/example/imagine-niji.ts)
- [custom zoom](https://github.com/erictik/midjourney-client/blob/main/example/customzoom.ts)
- [pan right](https://github.com/erictik/midjourney-client/blob/main/example/custompan.ts)
- [remix mode](https://github.com/erictik/midjourney-client/blob/main/example/variation-ws.ts)

## Example
Expand Down Expand Up @@ -254,11 +283,11 @@ To run the included example, you must have [Node.js](https://nodejs.org/en/) ins
If you find it valuable and would like to show your support, any donations would be greatly appreciated. Your contribution helps me maintain and improve the program.

<span style="word-spacing:20px">
<img src="images/ali.png" height="300"/>  
<img src="images/ali.png" height="300"/>
<img src="images/wechat.png" height="300"/>
<a href='https://ko-fi.com/erictik' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee' /></a>
</span>

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=erictik/midjourney-client&type=Date)](https://star-history.com/#erictik/midjourney-client&Date)
[![Star History Chart](https://api.star-history.com/svg?repos=erictik/midjourney-client&type=Date)](https://star-history.com/#erictik/midjourney-client&Date)
123 changes: 123 additions & 0 deletions example/custompan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import "dotenv/config";
import fs from 'fs';
import { Midjourney } from "../src";
/**
*
* a simple example of how to use the (custom pan) options with ws command
* ```
* npx tsx example/custompan.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, //enable ws is required for custom pan
});
await client.init();
const prompt =
"Blonde Boy plays with Golden Retreiever in dream-like grassy field ::3 happy :: blonde :: golden retriever :: green nature :: simple illustration";
const remixPrompt =
"empty ::5 grass ::2 dream-like grassy field ::3 green nature :: illustration --no woman, girl, human, dog, person";

/* comment out imagine and upscale if using load from file */
//imagine
const Imagine = await client.Imagine(
prompt,
(uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
}
);
console.log(Imagine);
if (!Imagine) {
console.log("no message");
return;
}

// Upscale U1
let U1CustomID = Imagine.options?.find((o) => o.label === "U1")?.custom;
if (!U1CustomID) {
console.log("no U1");
return;
}
const Upscale = await client.Custom({
msgId: <string>Imagine.id,
flags: Imagine.flags,
customId: U1CustomID,
loading: (uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
},
});

// comment out save and load if using imagine and upscale
// save Upscale post-imagine so image doesnt have to be generated every time testing on custom pan is run
//fs.writeFileSync('savedUpscale.json', JSON.stringify(Upscale, null, 2));

// load from file
//const jsonString = fs.readFileSync('savedUpscale.json', 'utf-8');
//const Upscale = JSON.parse(jsonString);

if(!Upscale){
console.log("no Upscale");
return;
}
console.log("UPSCALE:", Upscale);

// Custom Pan
const pan = Upscale?.options?.find((o) => o.label === "➡️");
if (!pan) {
console.log("no pan");
return;
}
const CustomPan = await client.Custom({
msgId: <string>Upscale.id,
flags: Upscale.flags,
content: `${remixPrompt}`,
customId: pan.custom,
loading: (uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
},
});
if (!CustomPan) {
console.log("no CustomPan");
return;
}
console.log("Custom Pan", CustomPan);


// UPSCALE AGAIN
U1CustomID = CustomPan.options?.find((o) => o.label === "U1")?.custom;
if (!U1CustomID) {
console.log("no U1");
return;
}
const Upscale2 = await client.Custom({
msgId: <string>CustomPan.id,
flags: CustomPan.flags,
customId: U1CustomID,
loading: (uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
},
});
if(!Upscale2){
console.log("no Upscale2");
return;
}
console.log("UPSCALE2:", Upscale2);


console.log("FINISHED");


// client.Close();
}
main()
.then(() => {
console.log("done");
})
.catch((err) => {
console.error(err);
process.exit(1);
});
Loading