Skip to content

Commit

Permalink
Post-deployment fixes (#1063)
Browse files Browse the repository at this point in the history
- fix initial service on new preset
- hide third party format properly
* fix image override model init
* tweak user id on preset create update
  • Loading branch information
sceuick authored Nov 3, 2024
1 parent 13378eb commit 2a16a60
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 27 deletions.
1 change: 1 addition & 0 deletions srv/api/user/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const createUserPreset = handle(async ({ userId, body, authed }) => {
const preset = {
...body,
service,
userId,
order: samplers?.order,
disabledSamplers: samplers?.disabled,
}
Expand Down
8 changes: 6 additions & 2 deletions srv/db/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export async function updateGenPreset(chatId: string, preset: string) {
export async function createUserPreset(userId: string, settings: AppSchema.GenSettings) {
const preset: AppSchema.UserGenPreset = {
kind: 'gen-setting',
userId,
...settings,
userId,
_id: v4(),
}

Expand Down Expand Up @@ -112,8 +112,12 @@ export async function deleteUserPresetKey(userId: string, presetId: string) {
export async function updateUserPreset(
userId: string,
presetId: string,
update: Partial<AppSchema.GenSettings>
update: Partial<AppSchema.UserGenPreset>
) {
if (update.userId) {
delete update.userId
}

if (update.registered) {
const prev = await getUserPreset(presetId)
update.registered = {
Expand Down
16 changes: 5 additions & 11 deletions web/pages/Character/form/ReelControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,16 @@ const ModelOverride: Component<{ state: string; setter: (override: string) => vo

createEffect(
on(
() => user.user?.images?.agnai?.model,
(id) => {
if (!id) return
() => user.user?.images?.agnai?.model + props.state,
() => {
const id = user.user?.images?.agnai?.model
if (props.state || !id || !state.models.length) return
console.log('setting', id)
props.setter(id)
}
)
)

createEffect(() => {
if (!options().length) return
const id = user.user?.images?.agnai?.model
if (!id) return

props.setter(id)
})

return (
<Show when={(user.sub?.tier.imagesAccess || user.user?.admin) && state.models.length > 0}>
<Select
Expand Down
2 changes: 2 additions & 0 deletions web/pages/GenerationPresets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TitleCard } from '/web/shared/Card'
import { Page } from '/web/Layout'
import PresetSettings from '/web/shared/PresetSettings'
import { getPresetEditor, getPresetForm } from '/web/shared/PresetSettings/types'
import { templates } from '/common/presets/templates'

export const GenerationPresetsPage: Component = () => {
const { updateTitle } = setComponentPageTitle('Preset')
Expand Down Expand Up @@ -194,6 +195,7 @@ export default GenerationPresetsPage

const emptyPreset: AppSchema.GenSettings = {
...defaultPresets.basic,
gaslight: templates.Universal,
service: '' as any,
name: '',
maxTokens: 300,
Expand Down
24 changes: 19 additions & 5 deletions web/shared/PresetSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
AdapterSetting,
ThirdPartyFormat,
} from '../../../common/adapters'
import { presetStore, settingStore, userStore } from '../../store'
import { presetStore, settingStore } from '../../store'
import { Card } from '../Card'
import { getFormEntries, getUsableServices, hidePresetSetting, storage } from '../util'
import { getFormEntries, getUsableServices, storage } from '../util'
import { createStore } from 'solid-js/store'
import Accordian from '../Accordian'
import { ServiceOption } from '../../pages/Settings/components/RegisteredSettings'
Expand All @@ -34,7 +34,6 @@ const PresetSettings: Component<
PresetProps & { noSave: boolean; store: PresetState; setter: SetPresetState }
> = (props) => {
const settings = settingStore()
const userState = userStore()
const pane = usePaneManager()
const [search, setSearch] = useSearchParams()
const [tab, setTab] = createSignal(+(search.preset_tab ?? '0'))
Expand All @@ -56,6 +55,21 @@ const PresetSettings: Component<
)
)

createEffect(
on(
() => (props.store.service || '') + services().length,
() => {
if (props.disabled) return
if (props.store.service) return
if (!services().length) return
if (props.store._id) return

console.log('new', services()[0].value)
props.setter('service', services()[0].value as any)
}
)
)

const sub = createMemo(() => {
if (props.store.service !== 'agnaistic') return
const match = settings.config.subs.find(
Expand Down Expand Up @@ -129,8 +143,8 @@ const PresetSettings: Component<
{ label: 'Featherless', value: 'featherless' },
{ label: 'Google AI Studio', value: 'gemini' },
]}
value={props.store.thirdPartyFormat ?? userState.user?.thirdPartyFormat ?? ''}
hide={hidePresetSetting(props.store, 'thirdPartyFormat')}
value={props.store.thirdPartyFormat}
hide={props.store.service !== 'kobold'}
onChange={(ev) => props.setter('thirdPartyFormat', ev.value as ThirdPartyFormat)}
/>

Expand Down
44 changes: 35 additions & 9 deletions web/shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as lf from 'localforage'
import { UnwrapBody, Validator, assertValid } from '/common/valid'
import { AIAdapter, MODE_SETTINGS, PresetAISettings, ThirdPartyFormat } from '/common/adapters'
import type { Option } from './Select'
import { Component, createEffect, JSX, onCleanup } from 'solid-js'
import { Component, createEffect, createSignal, JSX, on, onCleanup } from 'solid-js'
import type { UserState } from '../store'
import { AppSchema, UI } from '/common/types'
import { deepClone } from '/common/util'
Expand Down Expand Up @@ -645,16 +645,42 @@ export function hidePresetSetting(
state: Pick<PresetState, 'service' | 'thirdPartyFormat' | 'presetMode'>,
prop?: keyof PresetAISettings
) {
if (!prop) return false

if (state.presetMode && state.presetMode !== 'advanced') {
let initial = false
if (!prop) {
initial = false
} else if (state.presetMode && state.presetMode !== 'advanced') {
const enabled = MODE_SETTINGS[state.presetMode]?.[prop]
if (!enabled) return true
}
if (!enabled) initial = true
} else {
const valid = isValidServiceSetting(state, prop)
if (valid) initial = false
else initial = true
}

const [hide, setHide] = createSignal(initial)

createEffect(
on(
() => (state.service || '') + (state.thirdPartyFormat || '') + (state.presetMode || ''),
() => {
let next = false
if (!prop) {
next = false
} else if (state.presetMode && state.presetMode !== 'advanced') {
const enabled = MODE_SETTINGS[state.presetMode]?.[prop]
if (!enabled) next = true
} else {
const valid = isValidServiceSetting(state, prop)
if (valid) next = false
else next = true
}

setHide(next)
}
)
)

const valid = isValidServiceSetting(state, prop)
if (valid) return false
return true
return hide()
}

export function isValidServiceSetting(
Expand Down

0 comments on commit 2a16a60

Please sign in to comment.