Skip to content

Director Tools

Director Tools 提供图像增强和标签建议功能。

图像增强 (Augment Image)

使用 augmentImage 方法对图像进行增强处理:

typescript
import { NovelAI } from 'novelai-sdk-unofficial';
import { readFileSync, writeFileSync } from 'fs';

const client = new NovelAI({ apiKey: 'your-api-key' });

// 背景移除
const images = await client.image.augmentImage({
  image: readFileSync('input.png'),
  type: 'bg-removal',
  width: 1024,
  height: 1024,
});

writeFileSync('output.png', images[0]);

支持的增强类型

type描述
bg-removal背景移除
lineart线稿提取
sketch素描风格
colorize上色
emotion表情变换
declutter去杂乱

参数说明

参数类型必填描述
imageBuffer | string | ArrayBuffer输入图像
typeAugmentType增强类型
widthnumber输出宽度(必须与输入图像宽度匹配)
heightnumber输出高度(必须与输入图像高度匹配)
promptstring提示词(用于 colorize 等类型)
defrynumberDefry 级别(0-5)

注意

widthheight 必须与输入图像的实际尺寸匹配,否则 API 会返回 500 错误。

上色示例

typescript
const colorized = await client.image.augmentImage({
  image: readFileSync('sketch.png'),
  type: 'colorize',
  width: 1024,
  height: 1024,
  prompt: 'vibrant colors, detailed shading',
});

标签建议 (Suggest Tags)

使用 suggestTags 方法获取标签建议:

typescript
import { NovelAI } from 'novelai-sdk-unofficial';

const client = new NovelAI({ apiKey: 'your-api-key' });

// 获取标签建议
const tags = await client.image.suggestTags({
  prompt: '1girl, blue',
});

for (const tag of tags) {
  console.log(`${tag.tag}: ${tag.confidence} (${tag.count})`);
}

参数说明

参数类型默认值描述
promptstring必填不完整的标签查询
modelImageModel'nai-diffusion-4-5-full'图像模型
lang'en' | 'jp''en'语言

返回值

typescript
interface TagSuggestion {
  tag: string;        // 建议的标签
  confidence: number; // 置信度
  count: number;      // 使用次数
}

日语标签建议

typescript
const tags = await client.image.suggestTags({
  prompt: '女の子',
  lang: 'jp',
});

Low-Level API

如果需要更精细的控制,可以使用 Low-Level API:

typescript
import { APIClient } from 'novelai-sdk-unofficial/api';

const client = new APIClient({ apiKey: 'your-api-key' });

// 图像增强
const images = await client.image.augmentImage({
  image: base64String,
  req_type: 'bg-removal',
  width: 1024,
  height: 1024,
});

// 标签建议
const response = await client.image.suggestTags(
  'nai-diffusion-4-5-full',
  '1girl, blue',
  'en'
);

基于 MIT 许可证发布