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 | 去杂乱 |
参数说明
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
image | Buffer | string | ArrayBuffer | 是 | 输入图像 |
type | AugmentType | 是 | 增强类型 |
width | number | 是 | 输出宽度(必须与输入图像宽度匹配) |
height | number | 是 | 输出高度(必须与输入图像高度匹配) |
prompt | string | 否 | 提示词(用于 colorize 等类型) |
defry | number | 否 | Defry 级别(0-5) |
注意
width 和 height 必须与输入图像的实际尺寸匹配,否则 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})`);
}参数说明
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
prompt | string | 必填 | 不完整的标签查询 |
model | ImageModel | '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'
);