Skip to content

Commit

Permalink
fix: compatible with nai-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-fish committed Mar 10, 2024
1 parent cc585e7 commit d3df47f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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'),
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')) {
const buffer = Buffer.from(res.data, 'binary') // Ensure 'binary' encoding
const zip = new AdmZip(buffer)

Expand Down

0 comments on commit d3df47f

Please sign in to comment.