|
| 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