Skip to content

Commit

Permalink
Tweak disable ltm (#1052)
Browse files Browse the repository at this point in the history
- rename disable ltm to enable ltm
- show warning in embed content pane
- add link to settings modal in embed content warning
- remove refresh requirement after enabling ltm
- patreon: fix relationships not exist error
  • Loading branch information
sceuick authored Oct 12, 2024
1 parent 988acdb commit 27491b9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion srv/api/user/patreon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function identity(token: string) {
const tiers: Patreon.Tier[] =
identity.body.included?.filter((obj: Patreon.Include) => {
if (obj.type !== 'tier') return false
return obj.relationships.campaign?.data?.id === config.patreon.campaign_id
return obj.relationships?.campaign?.data?.id === config.patreon.campaign_id
}) || []

const tier = tiers.length
Expand Down
16 changes: 15 additions & 1 deletion web/pages/Memory/EmbedContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Match, Switch, createSignal } from 'solid-js'
import { Component, Match, Show, Switch, createSignal } from 'solid-js'
import { getStrictForm } from '/web/shared/util'
import { toastStore } from '/web/store/toasts'
import TextInput from '/web/shared/TextInput'
Expand All @@ -8,10 +8,14 @@ import Divider from '/web/shared/Divider'
import { slugify } from '/common/util'
import { embedApi } from '/web/store/embeddings'
import Select from '/web/shared/Select'
import { getStore } from '/web/store/create'
import { SolidCard } from '/web/shared/Card'
import { settingStore } from '/web/store'

export { EmbedContent as default }

const EmbedContent: Component = (props) => {
const user = getStore('user')()
let ref: any

const options = ['Article', 'PDF', 'Text file', 'Plain Text']
Expand Down Expand Up @@ -87,6 +91,16 @@ const EmbedContent: Component = (props) => {

return (
<form ref={ref} class="flex flex-col gap-2">
<Show when={user.user?.disableLTM ?? true}>
<SolidCard bg="premium-700">
You need need to enable{' '}
<b class="underline hover:cursor-pointer" onClick={() => settingStore.modal(true)}>
Embeddings/Long-Term Memory
</b>{' '}
in your Settings
</SolidCard>
</Show>

<Select
items={options.map((value) => ({ label: `Embed: ${value}`, value }))}
fieldName="embed-type"
Expand Down
9 changes: 4 additions & 5 deletions web/pages/Settings/AISettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ const AISettings: Component<{

<Show when={ready()}>
<Toggle
fieldName="disableLTM"
value={state.user?.disableLTM ?? true}
label="Disable Long-Term Memory"
helperMarkdown={`Improves site performance. Disable long-term memory if your chat is _laggy_ and unresponsive.
**Refresh required for this change to take effect**
fieldName="enableLTM"
value={!(state.user?.disableLTM ?? true)}
label="Enable Embeddings/Long-Term Memory"
helperMarkdown={`Improves site performance when disabled. Disable long-term memory if your chat is _laggy_ and unresponsive.
`}
/>

Expand Down
5 changes: 3 additions & 2 deletions web/pages/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ const Settings: Component<{ footer?: (children: any) => void }> = (props) => {
textToSpeechFilterActions,

elevenLabsApiKey,

enableLTM,
...base
} = body

userStore.updateConfig({
...base,
disableLTM: !enableLTM,
adapterConfig,
hordeWorkers: workers(),
hordeModels: models(),
Expand Down Expand Up @@ -220,7 +221,7 @@ const settingsForm = {
scaleUrl: 'string?',
claudeApiKey: 'string?',
logPromptsToBrowserConsole: 'boolean?',
disableLTM: 'boolean?',
enableLTM: 'boolean?',

useLocalPipeline: 'boolean?',

Expand Down
3 changes: 3 additions & 0 deletions web/store/embeddings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export const embedApi = {
const embeds = ids.map((id) => ({ id, state: 'not-loaded' }))
setter({ embeds })
},
initSimiliary: () => {
post('initSimilarity', { model: models.embedding })
},
encode,
decode,
embedChat,
Expand Down
8 changes: 8 additions & 0 deletions web/store/embeddings/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const handlers: {
post('decoding', { id: msg.id, text: result })
},
initSimilarity: async (msg) => {
if (EMBED_INITED) {
console.log('[embed] already inited')
return
}
EMBED_INITED = true
Embedder = await pipeline('feature-extraction', msg.model, {
// quantized: true,
Expand All @@ -55,6 +59,10 @@ const handlers: {
post('embedLoaded', {})
},
initCaptioning: async (msg) => {
if (CAPTION_INITED) {
return
}

CAPTION_INITED = true
console.log(`[caption] loading`)

Expand Down
9 changes: 8 additions & 1 deletion web/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
setRootVariable,
} from '../shared/colors'
import { UserType } from '/common/types/admin'
import { embedApi } from './embeddings'

const BACKGROUND_KEY = 'ui-bg'
export const ACCOUNT_KEY = 'agnai-username'
Expand Down Expand Up @@ -376,11 +377,17 @@ export const userStore = createStore<UserState>(
}
},

async updateConfig(_, config: ConfigUpdate) {
async updateConfig({ user: prev }, config: ConfigUpdate) {
const res = await usersApi.updateConfig(config)
if (res.error) toastStore.error(`Failed to update config: ${res.error}`)
if (res.result) {
window.usePipeline = res.result.useLocalPipeline

const prevLTM = prev?.disableLTM ?? true
if (prevLTM && config.disableLTM === false) {
embedApi.initSimiliary()
}

toastStore.success(`Updated settings`)
return { user: res.result }
}
Expand Down

0 comments on commit 27491b9

Please sign in to comment.