Skip to content

Commit 7d6f0f5

Browse files
committed
chore: add vibe transfer example and update README.md
1 parent ad6134c commit 7d6f0f5

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ for (const image of images) {
202202
}
203203
```
204204

205+
### Vibe Transfer (V4 model only)
206+
207+
All V4 models support vibe transfer, which allows you to transfer the artistic style and mood from reference images to your generated content.
208+
209+
```javascript
210+
import { NovelAI, Model, Resolution, parseImage } from "nekoai-js";
211+
212+
// Initialize client
213+
const client = new NovelAI({
214+
token: "your_access_token",
215+
});
216+
217+
// Parse reference image for vibe transfer
218+
const vibeReference = await parseImage("./input/reference_style.png");
219+
220+
// Generate image with vibe transfer
221+
const images = await client.generateImage({
222+
prompt: "1girl, cute, detailed",
223+
model: Model.V4_5,
224+
resPreset: Resolution.NORMAL_PORTRAIT,
225+
reference_image_multiple: [vibeReference.base64], // Reference image will be converted vibe token (process in the background)
226+
reference_information_extracted_multiple: [0.7], // Extraction strength (0.0-1.0)
227+
steps: 30,
228+
seed: 3417044607,
229+
});
230+
231+
// Process the resulting images
232+
for (const image of images) {
233+
await image.save("./output");
234+
}
235+
```
236+
205237
### Image to Image
206238

207239
To perform `img2img` action, set `action` parameter to `Action.IMG2IMG`, and provide a source image. Use the `parseImage` utility to handle multiple image formats seamlessly.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const {
2+
NovelAI,
3+
Model,
4+
Resolution,
5+
Sampler,
6+
parseImage,
7+
} = require("nekoai-js");
8+
const Stream = require("stream");
9+
require("dotenv").config();
10+
11+
// Test function for V4 model generation
12+
async function testModelV45Full() {
13+
const client = new NovelAI({
14+
token: process.env.NOVELAI_TOKEN,
15+
verbose: true,
16+
});
17+
18+
console.log("Testing Model V4.5 Vibe Transfer generation...");
19+
20+
try {
21+
const vibe_reference = await parseImage(
22+
"./examples/input/vibe_reference.png",
23+
);
24+
25+
const images = await client.generateImage(
26+
{
27+
prompt: "1girl, cute",
28+
negative_prompt: "1234",
29+
model: Model.V4_5,
30+
resPreset: Resolution.NORMAL_PORTRAIT,
31+
seed: 3417044607,
32+
steps: 30,
33+
scale: 5,
34+
sampler: Sampler.EULER_ANC,
35+
reference_image_multiple: [vibe_reference.base64], // the reference image will be re-encoded as vibe token
36+
reference_information_extracted_multiple: [0.7],
37+
ucPreset: 3,
38+
},
39+
false,
40+
true,
41+
); // Set verbose to true to see Anlas cost
42+
43+
if (images.length > 0) {
44+
console.log(`Generated ${images.length} image(s)`);
45+
// Save the images to the output directory
46+
for (const [index, image] of images.entries()) {
47+
const path = await image.save(
48+
"./examples/output/model-v4-5-full-vibe.png",
49+
);
50+
console.log(`Saved image ${index + 1} to ${path}`);
51+
}
52+
} else {
53+
console.log("No images were generated");
54+
}
55+
} catch (error) {
56+
console.error("Error generating image:", error);
57+
}
58+
}
59+
60+
// Run the test if this script is executed directly
61+
if (require.main === module) {
62+
testModelV45Full().catch(console.error);
63+
}
64+
65+
module.exports = { testModelV45Full };

0 commit comments

Comments
 (0)