Skip to content

Commit e2e07c4

Browse files
committed
fix: fix emotion change logic, refine custom host logic
1 parent 8232e59 commit e2e07c4

File tree

7 files changed

+25
-56
lines changed

7 files changed

+25
-56
lines changed

examples/custom-host-test.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@ const {
55
Sampler,
66
createCustomHost,
77
} = require("nekoai-js");
8-
require("dotenv").config();
98

109
// Test function for custom host
1110
async function testCustomHost() {
1211
const client = new NovelAI({
13-
token: process.env.NOVELAI_TOKEN,
12+
token: process.env.CUSTOM_TOKEN,
1413
});
1514

1615
console.log("Testing custom host...");
1716

1817
// Create a custom host (this example uses the official API endpoint, but you can use any compatible server)
1918
const customHost = createCustomHost(
20-
"https://api.novelai.net", // URL - replace with your custom host
21-
"application/x-zip-compressed", // Accept header
22-
"custom-api", // Name for the host (used in filenames)
19+
"https://image.novelai.net", // Custom host URL
2320
);
2421

2522
try {
@@ -52,29 +49,6 @@ async function testCustomHost() {
5249
} else {
5350
console.log("No images were generated");
5451
}
55-
56-
// Also test a director tool with custom host
57-
console.log("Testing director tool with custom host...");
58-
59-
try {
60-
// Use the web endpoint for director tools (proper custom host would use your own endpoint)
61-
const directorHost = createCustomHost(
62-
"https://image.novelai.net",
63-
"binary/octet-stream",
64-
"custom-director",
65-
);
66-
67-
// Try a director tool with the custom host
68-
// Note: You'll need an existing image file at this path
69-
const lineArtResult = await client.lineArt(
70-
"./examples/input/image.png",
71-
directorHost,
72-
);
73-
const savePath = await lineArtResult.save("./examples/output");
74-
console.log(`Line art saved to ${savePath}`);
75-
} catch (error) {
76-
console.error("Error with director tool using custom host:", error);
77-
}
7852
} catch (error) {
7953
console.error("Error generating image with custom host:", error);
8054
}

examples/director-tools-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ async function testDirectorTools() {
8888
try {
8989
const emotionResult = await client.changeEmotion({
9090
image: imageInput,
91-
emotion: EmotionOptions.HAPPY,
92-
prompt: "laughing",
91+
emotion: "happy",
92+
prompt: "",
9393
emotionLevel: EmotionLevel.NORMAL,
9494
});
9595
const savePath = await emotionResult.save(

examples/model-v4-5-multichar-test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ async function testModelV45MultiChar() {
1313
const images = await client.generateImage(
1414
{
1515
prompt: "two people, classroom, school uniform, detailed background",
16-
model: Model.V4_5_CUR,
17-
resPreset: Resolution.NORMAL_LANDSCAPE,
16+
model: "nai-diffusion-4-5-curated",
17+
resPreset: "normal_landscape",
1818
steps: 28,
1919
scale: 5.5,
20-
sampler: Sampler.EULER_ANC,
21-
noiseSchedule: Noise.KARRAS,
20+
sampler: "k_euler_ancestral",
21+
noiseSchedule: "karras",
2222
negativePrompt:
2323
"nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit",
2424
// Character prompts for multiple characters
@@ -45,7 +45,9 @@ async function testModelV45MultiChar() {
4545
console.log(`Generated ${images.length} image(s)`);
4646
// Save the images to the output directory
4747
for (const [index, image] of images.entries()) {
48-
const path = await image.save("./examples/output/model-v4-5-multichar-test.png");
48+
const path = await image.save(
49+
"./examples/output/model-v4-5-multichar-test.png",
50+
);
4951
console.log(`Saved image ${index + 1} to ${path}`);
5052
}
5153
} else {

src/client.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "./constants";
1515
import { Image } from "./image";
1616
import {
17-
ChangeEmotionOptions,
1817
DirectorRequest,
1918
HostInstance,
2019
ImageInput,
@@ -599,31 +598,32 @@ export class NovelAI {
599598
/**
600599
* Change the emotion of a character in an image
601600
*
602-
* @param options - Options for changing emotion
603-
* @param options.image - Image input (path, Blob, File, URL, etc.)
604-
* @param options.emotion - Target emotion to change to
605-
* @param options.prompt - Additional prompt to add to the request
606-
* @param options.emotionLevel - Level of emotion change (0-5, optional)
601+
* @param image - Image input (path, Blob, File, URL, etc.)
607602
* @param host - Host to use for the request (optional)
603+
* @param emotion - Target emotion to change to
604+
* @param prompt - Additional prompt to add to the request
605+
* @param emotionLevel - Level of emotion change (0-5, optional)
608606
* @returns Promise resolving to an Image object
609607
*/
610608
async changeEmotion(
611-
options: ChangeEmotionOptions,
609+
image: ImageInput,
612610
host?: Host | HostInstance,
611+
emotion: string = EmotionOptions.NEUTRAL,
612+
prompt: string = "",
613+
emotionLevel: EmotionLevel = EmotionLevel.NORMAL,
614+
613615
): Promise<Image> {
614-
const parsedImage = await parseImage(options.image);
616+
const parsedImage = await parseImage(image);
615617

616-
// Create the prompt string in the format "originalEmotion;;targetEmotion,"
617-
const originalEmotion = options.prompt || EmotionOptions.NEUTRAL;
618-
const prompt = `${originalEmotion};;${options.emotion},`;
618+
const final_prompt = `${emotion};;${prompt}`;
619619

620620
const request: DirectorRequest = {
621621
req_type: DirectorTools.EMOTION,
622622
width: parsedImage.width,
623623
height: parsedImage.height,
624624
image: parsedImage.base64,
625-
prompt,
626-
defry: options.emotionLevel ?? EmotionLevel.NORMAL,
625+
prompt: final_prompt,
626+
defry: emotionLevel ?? EmotionLevel.NORMAL,
627627
};
628628

629629
return this.useDirectorTool(request, host);

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const HOST_INSTANCES: Record<Host, HostInstance> = {
3535
*/
3636
export function createCustomHost(
3737
url: string,
38-
accept: string,
38+
accept: string = "binary/octet-stream",
3939
name = "custom",
4040
): HostInstance {
4141
return {

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export {
2222

2323
// Export types
2424
export type {
25-
ChangeEmotionOptions,
2625
CharacterCaption,
2726
CharacterPrompt,
2827
CustomHost,

src/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,6 @@ export type DirectorRequest =
255255
| ColorizeRequest
256256
| EmotionRequest;
257257

258-
export interface ChangeEmotionOptions {
259-
image: ImageInput;
260-
emotion: EmotionOptions | string;
261-
prompt?: string;
262-
emotionLevel?: EmotionLevel | number;
263-
}
264258

265259
export interface NovelAIOptions {
266260
token: string;

0 commit comments

Comments
 (0)