Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compatible with nai-v3 #241

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface PromptConfig {
}

export const PromptConfig: Schema<PromptConfig> = Schema.object({
basePrompt: Schema.computed(Schema.string().role('textarea'), options).description('默认附加的标签。').default('masterpiece, best quality'),
basePrompt: Schema.computed(Schema.string().role('textarea'), options).description('默认附加的标签。').default('best quality, amazing quality, very aesthetic, absurdres'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change affects every backend not only nai-v3, would it make nai-v1 or other backends generate worse images? If no, it is okay for me.

这个改动影响了所有的后端不仅仅是 nai-v3,它会让 nai-v1 或其他后端生成更糟的图片吗?如否,它对我来说是可以的。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有测试过,我过会儿测试一下
或者也可以把预设 model 改为 nai-v3,因为 v1 已经被官方标记为不推荐了

Copy link
Member

@MaikoTan MaikoTan Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者也可以把预设 model 改为 nai-v3,因为 v1 已经被官方标记为不推荐了

This is okay to me, can you change the default model to nai-v3 as well?

这听起来可以,你能顺便改默认模型到 nai-v3 吗?

After this, I will merge the PR.

之后,我会合并 PR。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果修改默认 model 为 nai-v3,我们是否应该将 scale 的预设值同步修改为 5?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果修改默认 model 为 nai-v3,我们是否应该将 scale 的预设值同步修改为 5?

Sure, will you double-check and change all relative parameters to match the nai v3 afterwards?

当然,您会仔细检查并更改所有相关参数以匹配 nai v3 吗?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will you double-check and change all relative parameters to match the nai v3 afterwards?

当然,您会仔细检查并更改所有相关参数以匹配 nai v3 吗?

done

negativePrompt: Schema.computed(Schema.string().role('textarea'), options).description('默认附加的反向标签。').default(ucPreset),
forbidden: Schema.computed(Schema.string().role('textarea'), options).description('违禁词列表。请求中的违禁词将会被自动删除。').default(''),
defaultPromptSw: Schema.boolean().description('是否启用默认标签。').default(false),
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export function apply(ctx: Context, config: Config) {
case 'login':
case 'token':
case 'naifu': {
parameters.params_version = 1
parameters.sampler = sampler.sd2nai(options.sampler, model)
parameters.image = image?.base64 // NovelAI / NAIFU accepts bare base64 encoded image
if (config.type === 'naifu') return parameters
Expand All @@ -320,6 +321,8 @@ export function apply(ctx: Context, config: Config) {
}
parameters.dynamic_thresholding = options.decrisper ?? config.decrisper
if (model === 'nai-diffusion-3') {
parameters.legacy = false
parameters.legacy_v3_extend = false
parameters.sm_dyn = options.smeaDyn ?? config.smeaDyn
parameters.sm = (options.smea ?? config.smea) || parameters.sm_dyn
parameters.noise_schedule = options.scheduler ?? config.scheduler
Expand All @@ -332,6 +335,12 @@ export function apply(ctx: Context, config: Config) {
parameters.sm_dyn = false
delete parameters.noise_schedule
}
// Max scale for nai-v3 is 10, but not 20.
// If the given value is greater than 10,
// we can assume it is configured with an older version (max 20)
if (parameters.scale > 10) {
parameters.scale = parameters.scale / 2
}
}
return { model, input: prompt, parameters: omit(parameters, ['prompt']) }
}
Expand Down Expand Up @@ -446,8 +455,8 @@ export function apply(ctx: Context, config: Config) {
// event: newImage
// id: 1
// data:

if (res.headers.get('content-type') === 'application/x-zip-compressed') {
// ↓ nai-v3
if (res.headers.get('content-type') === 'application/x-zip-compressed' || res.headers.get('content-disposition')?.includes('.zip')) {
MaikoTan marked this conversation as resolved.
Show resolved Hide resolved
const buffer = Buffer.from(res.data, 'binary') // Ensure 'binary' encoding
const zip = new AdmZip(buffer)

Expand Down
Loading