mirror of
https://github.com/koishijs/novelai-bot
synced 2025-01-09 08:59:21 +08:00
fix: fix missing types
This commit is contained in:
parent
5bc69a3f1a
commit
528dd1c99d
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "koishi-plugin-novelai",
|
||||
"description": "Generate images by NovelAI",
|
||||
"version": "1.10.6",
|
||||
"version": "1.10.8",
|
||||
"main": "lib/index.js",
|
||||
"typings": "lib/index.d.ts",
|
||||
"files": [
|
||||
|
27
src/index.ts
27
src/index.ts
@ -1,6 +1,6 @@
|
||||
import { Context, Dict, Logger, Quester, Schema, segment, Session, Time, trimSlash } from 'koishi'
|
||||
import { StableDiffusionWebuiRes, StableDiffusionWebuiReq } from './types'
|
||||
import { download, getImageSize, login, NetworkError, resizeInput } from './utils'
|
||||
import { StableDiffusionWebUI } from './types'
|
||||
import { download, getImageSize, login, NetworkError, project, resizeInput } from './utils'
|
||||
import {} from '@koishijs/plugin-help'
|
||||
|
||||
export const reactive = true
|
||||
@ -57,7 +57,8 @@ export const Config = Schema.intersect([
|
||||
type: Schema.union([
|
||||
Schema.const('token' as const).description('授权令牌'),
|
||||
...process.env.KOISHI_ENV === 'browser' ? [] : [Schema.const('login' as const).description('账号密码')],
|
||||
Schema.const('naifu' as const).description('NAIFU'),
|
||||
Schema.const('naifu' as const).description('naifu'),
|
||||
Schema.const('sd-webui' as const).description('sd-webui'),
|
||||
] as const).description('登录方式'),
|
||||
}).description('登录设置'),
|
||||
Schema.union([
|
||||
@ -88,8 +89,8 @@ export const Config = Schema.intersect([
|
||||
}),
|
||||
Schema.object({
|
||||
type: Schema.const('sd-webui' as const),
|
||||
endpoint: Schema.string().description('Stable Diffusion WebUI 服务器地址。').required(),
|
||||
})
|
||||
endpoint: Schema.string().description('API 服务器地址。').required(),
|
||||
}),
|
||||
] as const),
|
||||
Schema.object({
|
||||
model: Schema.union(models).description('默认的生成模型。').default('nai'),
|
||||
@ -358,13 +359,21 @@ export function apply(ctx: Context, config: Config) {
|
||||
authorization: 'Bearer ' + token,
|
||||
},
|
||||
data: config.type === 'sd-webui'
|
||||
? { prompt: input, n_samples: parameters.n_samples, sampler_index: parameters.sampler, negative_prompt: parameters.uc, seed: parameters.seed } as StableDiffusionWebuiReq
|
||||
? {
|
||||
prompt: input,
|
||||
...project(parameters, {
|
||||
n_samples: 'n_samples',
|
||||
seed: 'seed',
|
||||
sampler_index: 'sampler',
|
||||
negative_prompt: 'uc',
|
||||
}),
|
||||
}
|
||||
: config.type === 'naifu'
|
||||
? { ...parameters, prompt: input }
|
||||
: { model, input, parameters },
|
||||
? { ...parameters, prompt: input }
|
||||
: { model, input, parameters },
|
||||
}).then((res) => {
|
||||
if (config.type === 'sd-webui') {
|
||||
return (res.data as StableDiffusionWebuiRes).images[0]
|
||||
return (res.data as StableDiffusionWebUI.Response).images[0]
|
||||
}
|
||||
// event: newImage
|
||||
// id: 1
|
||||
|
68
src/types.ts
68
src/types.ts
@ -38,38 +38,40 @@ export interface Subscription {
|
||||
trainingStepsLeft: TrainingStepsLeft
|
||||
}
|
||||
|
||||
export interface StableDiffusionWebuiReq {
|
||||
prompt: string
|
||||
negative_prompt?: string
|
||||
enable_hr?: boolean
|
||||
denoising_strength?: number
|
||||
firstphase_width?: number
|
||||
firstphase_height?: number
|
||||
styles?: string[]
|
||||
seed?: number
|
||||
subseed?: number
|
||||
subseed_strength?: number
|
||||
seed_resize_from_h?: number
|
||||
seed_resize_from_w?: number
|
||||
batch_size?: number
|
||||
n_iter?: number
|
||||
steps?: number,
|
||||
cfg_scale?: number
|
||||
width?: number
|
||||
height?: number
|
||||
restore_faces?: boolean
|
||||
tiling?: boolean
|
||||
eta?: number
|
||||
s_churn?: number
|
||||
s_tmax?: number
|
||||
s_tmin?: number
|
||||
s_noise?: number
|
||||
sampler_index?: string
|
||||
}
|
||||
export namespace StableDiffusionWebUI {
|
||||
export interface Request {
|
||||
prompt: string
|
||||
negative_prompt?: string
|
||||
enable_hr?: boolean
|
||||
denoising_strength?: number
|
||||
firstphase_width?: number
|
||||
firstphase_height?: number
|
||||
styles?: string[]
|
||||
seed?: number
|
||||
subseed?: number
|
||||
subseed_strength?: number
|
||||
seed_resize_from_h?: number
|
||||
seed_resize_from_w?: number
|
||||
batch_size?: number
|
||||
n_iter?: number
|
||||
steps?: number
|
||||
cfg_scale?: number
|
||||
width?: number
|
||||
height?: number
|
||||
restore_faces?: boolean
|
||||
tiling?: boolean
|
||||
eta?: number
|
||||
s_churn?: number
|
||||
s_tmax?: number
|
||||
s_tmin?: number
|
||||
s_noise?: number
|
||||
sampler_index?: string
|
||||
}
|
||||
|
||||
export interface StableDiffusionWebuiRes {
|
||||
/** Image list in base64 format */
|
||||
images: string[]
|
||||
parameters: any
|
||||
info: any
|
||||
export interface Response {
|
||||
/** Image list in base64 format */
|
||||
images: string[]
|
||||
parameters: any
|
||||
info: any
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,14 @@ import {
|
||||
import imageSize from 'image-size'
|
||||
import { Subscription } from './types'
|
||||
|
||||
export function project(object: {}, mapping: {}) {
|
||||
const result = {}
|
||||
for (const key in mapping) {
|
||||
result[key] = object[mapping[key]]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export interface Size {
|
||||
width: number
|
||||
height: number
|
||||
|
Loading…
Reference in New Issue
Block a user