Skip to content

Commit

Permalink
Fix no-reply parent ids (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Jul 3, 2024
1 parent e28fbd5 commit 75abbd5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common/horde-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const defaults = {
image: {
sampler: SD_SAMPLER['DPM++ 2M'],
model: 'Deliberate',
negative: `disfigured, ugly, deformed, poorly, censor, censored, blurry, lowres, fused, malformed, watermark, misshapen, duplicated, grainy, distorted, signature`,
negative: ``,
},
}

Expand Down
2 changes: 1 addition & 1 deletion srv/api/chat/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@ function getNewMessageParent(body: GenRequest, userMsg: AppSchema.ChatMessage |

case 'retry':
case 'continue':
case 'request':
return body.parent || ''

case 'request':
case 'ooc':
case 'self':
case 'send':
Expand Down
20 changes: 16 additions & 4 deletions srv/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { handleSDImage } from './stable-diffusion'
import { sendGuest, sendMany, sendOne } from '../api/ws'
import { handleHordeImage } from './horde'

const DEFAULT_NEGATIVE = `disfigured, deformed, poorly, blurry, lowres, fused, malformed, misshapen, duplicated, grainy, distorted`
const DEFAULT_NEGATIVE = ``

export async function generateImage(
{ user, chatId, messageId, ...opts }: ImageGenerateRequest,
Expand Down Expand Up @@ -98,17 +98,29 @@ export async function generateImage(
try {
switch (imageSettings?.type || 'horde') {
case 'novel':
image = await handleNovelImage({ user, prompt, negative }, log, guestId)
image = await handleNovelImage(
{ user, prompt, negative, settings: imageSettings },
log,
guestId
)
break

case 'sd':
case 'agnai':
image = await handleSDImage({ user, prompt, negative }, log, guestId)
image = await handleSDImage(
{ user, prompt, negative, settings: imageSettings },
log,
guestId
)
break

case 'horde':
default:
image = await handleHordeImage({ user, prompt, negative }, log, guestId)
image = await handleHordeImage(
{ user, prompt, negative, settings: imageSettings },
log,
guestId
)
break
}
} catch (ex: any) {
Expand Down
2 changes: 0 additions & 2 deletions srv/image/novel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { NovelSettings } from '../../common/types/image-schema'

const baseUrl = `https://image.novelai.net/ai`

// const negative_prompt = `disfigured, ugly, deformed, poorly, censor, censored, blurry, lowres, fused, malformed, watermark, misshapen, duplicated, grainy, distorted, signature`

const defaultSettings: NovelSettings = {
type: 'novel',
model: NOVEL_IMAGE_MODEL.Full,
Expand Down
9 changes: 5 additions & 4 deletions srv/image/stable-diffusion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export type SDRequest = {
}

export const handleSDImage: ImageAdapter = async (opts, log, guestId) => {
const { user } = opts
const config = await getConfig(user)
const config = await getConfig(opts)
const payload = getPayload(config.kind, opts, config.model)

logger.debug(payload, 'Image: Stable Diffusion payload')
Expand Down Expand Up @@ -81,14 +80,16 @@ export const handleSDImage: ImageAdapter = async (opts, log, guestId) => {
return { ext: 'png', content: buffer }
}

async function getConfig(user: AppSchema.User): Promise<{
async function getConfig({ user, settings }: ImageRequestOpts): Promise<{
kind: 'user' | 'agnai'
host: string
params?: string
model?: AppSchema.ImageModel
}> {
const type = settings?.type || user.images?.type

const userHost = user.images?.sd.url || defaultSettings.url
if (user.images?.type !== 'agnai') {
if (type !== 'agnai') {
return { kind: 'user', host: userHost }
}

Expand Down
2 changes: 2 additions & 0 deletions srv/image/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppSchema } from '../../common/types/schema'
import { AppLog } from '../logger'
import { BaseImageSettings } from '/common/types/image-schema'

export type ImageGenerateRequest = {
user: AppSchema.User
Expand All @@ -18,6 +19,7 @@ export type ImageRequestOpts = {
user: AppSchema.User
prompt: string
negative: string
settings: BaseImageSettings | undefined
}

export type ImageAdapter = (
Expand Down
5 changes: 5 additions & 0 deletions web/pages/Chat/ChatDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ const ChatDetail: Component = () => {
ev.preventDefault()
chatStore.option({ options: false, modal: 'graph' })
}

if (ev.key === 'p') {
ev.preventDefault()
msgStore.createImage()
}
}

document.addEventListener('keydown', keyboardShortcuts)
Expand Down
5 changes: 3 additions & 2 deletions web/shared/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
maxWidth?: 'full' | 'half'
maxHeight?: boolean
fixedHeight?: boolean
transparent?: boolean
onSubmit?: (ev: Event & { currentTarget: HTMLFormElement }) => void
tabs?: TabHook

Expand Down Expand Up @@ -44,7 +45,7 @@ const Modal: Component<Props> = (props) => {

return (
<Show when={props.show}>
<div class="fixed inset-x-0 top-0 z-[100] items-center justify-center px-4 sm:inset-0 sm:flex sm:items-center sm:justify-center">
<div class="fixed inset-x-0 top-0 z-[100] items-center justify-center px-4 sm:inset-0 sm:flex sm:items-center sm:justify-center">
<div class="fixed inset-0 -z-10 opacity-40 transition-opacity">
<div class="absolute inset-0 bg-black" />
</div>
Expand All @@ -53,7 +54,7 @@ const Modal: Component<Props> = (props) => {
ref={autofocus}
onSubmit={props.onSubmit || defaultSubmit}
class={`modal-height bg-900 z-50 my-auto w-[calc(100vw-16px)] overflow-hidden rounded-lg shadow-md shadow-black transition-all ${width()} `}
classList={{ 'h-full': props.maxHeight }}
classList={{ 'h-full': props.maxHeight, 'opacity-80': props.transparent }}
role="dialog"
aria-modal="true"
aria-label={props.ariaLabel}
Expand Down
1 change: 1 addition & 0 deletions web/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function getMaxChatWidth(chatWidth: UserState['ui']['chatWidth']) {
export const storage = {
getItem,
setItem,

removeItem,
clear,

Expand Down

0 comments on commit 75abbd5

Please # to comment.