Skip to content

Commit

Permalink
rename server connections to connection view models
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdjohnson committed Nov 1, 2024
1 parent 9545982 commit 36aca9d
Show file tree
Hide file tree
Showing 39 changed files with 208 additions and 200 deletions.
10 changes: 4 additions & 6 deletions src/components/ChatBoxInputRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Paperclip from '~/icons/Paperclip'
import ChevronDown from '~/icons/ChevronDown'

import { lightboxStore } from '~/features/lightbox/LightboxStore'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

const ChatBoxInputRow = observer(
({
Expand Down Expand Up @@ -81,7 +81,7 @@ const ChatBoxInputRow = observer(
}
}

const noModelSelected = !connectionModelStore.selectedModelName
const noModelSelected = !connectionStore.selectedModelName
const inputDisabled =
incomingMessageStore.isGettingData || noModelSelected || !!lightboxStore.lightboxMessage

Expand All @@ -106,9 +106,7 @@ const ChatBoxInputRow = observer(
(noModelSelected && 'tooltip cursor-not-allowed')
}
data-tip={
connectionModelStore.isAnyServerConnected
? 'No Models Selected'
: 'Server is not connected'
connectionStore.isAnyServerConnected ? 'No Models Selected' : 'Server is not connected'
}
>
<div
Expand Down Expand Up @@ -204,7 +202,7 @@ const ChatBoxInputRow = observer(
tabIndex={0}
type="button"
className="btn btn-active hidden rounded-none rounded-bl-md md:flex"
disabled={inputDisabled || connectionModelStore.isImageGenerationMode}
disabled={inputDisabled || connectionStore.isImageGenerationMode}
onClick={() => settingStore.openSettingsModal('personas')}
>
{personaStore.selectedPersona?.name || 'No personas selected'}
Expand Down
10 changes: 5 additions & 5 deletions src/components/ChatBoxPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { personaStore } from '~/core/PersonaStore'
import AttachmentWrapper from '~/components/AttachmentWrapper'
import FunTitle from '~/components/FunTitle'
import ToolTip from '~/components/Tooltip'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

type StepProps = { isCompleted?: boolean; type?: 'primary' | 'secondary'; inCompleteIcon?: string }

Expand All @@ -31,22 +31,22 @@ const Step = ({

const ChatBoxPrompt = observer(() => {
const activeConnectionTypes = useMemo(() => {
const connectionsTypes = _.chain(connectionModelStore.connections)
const connectionsTypes = _.chain(connectionStore.connections)
.filter('isConnected')
.map('type')
.value()

return new Set(connectionsTypes)
}, [connectionModelStore.connections])
}, [connectionStore.connections])

const anyConnectionHasModels = useMemo(() => {
for (const connection of connectionModelStore.connections) {
for (const connection of connectionStore.connections) {
if (!_.isEmpty(connection.models)) {
return true
}
}
return false
}, [connectionModelStore.connections])
}, [connectionStore.connections])
return (
<div className="hero my-auto">
<div className="hero-content w-fit text-center">
Expand Down
4 changes: 2 additions & 2 deletions src/components/EnabledCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Control, Controller } from 'react-hook-form'
import { SnapshotIn } from 'mobx-state-tree'

import { IConnectionDataModel } from '~/core/types'
import { ServerConnectionTypes } from '~/core/connections/servers'
import { ConnectionViewModelTypes } from '~/core/connection/viewModels'

type EnabledCheckboxProps = {
connection: ServerConnectionTypes
connection: ConnectionViewModelTypes
control: Control<SnapshotIn<IConnectionDataModel>>
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/HostInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import Question from '~/icons/Question'
import Refresh from '~/icons/Refresh'

import FormInput from '~/components/form/FormInput'
import { ServerConnectionTypes } from '~/core/connections/servers'
import { ConnectionViewModelTypes } from '~/core/connection/viewModels'
import { IConnectionDataModel } from '~/core/types'

type HostInputProps = {
connection: ServerConnectionTypes
connection: ConnectionViewModelTypes
isEnabled: boolean
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/ModelRefreshButton.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { observer } from 'mobx-react-lite'

import Refresh from '~/icons/Refresh'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

const ModelRefreshButton = observer(
({ small = false, shouldShow = false }: { small?: boolean; shouldShow?: boolean }) => {
const noServer = !connectionModelStore.isAnyServerConnected
const noServer = !connectionStore.isAnyServerConnected

return (
(shouldShow || noServer) && (
<button
className={'btn btn-ghost align-middle ' + (small && 'px-2')}
type="button"
onClick={() => connectionModelStore.refreshModels()}
onClick={() => connectionStore.refreshModels()}
title="Refresh models"
>
<Refresh />
Expand Down
4 changes: 2 additions & 2 deletions src/components/ModelSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import _ from 'lodash'

import ChevronDown from '~/icons/ChevronDown'
import { settingStore } from '~/core/SettingStore'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

const ModelSelector = observer(() => {
const { selectedModelLabel, isAnyServerConnected, selectedConnection } = connectionModelStore
const { selectedModelLabel, isAnyServerConnected, selectedConnection } = connectionStore
const noServer = !isAnyServerConnected

const label = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import FunTitle from '~/components/FunTitle'
import ToolTip from '~/components/Tooltip'

import { settingStore } from '~/core/SettingStore'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

import Warning from '~/icons/Warning'
import Bars3 from '~/icons/Bars3'
Expand All @@ -32,7 +32,7 @@ const KeyboardTooltip = ({ command, children }: PropsWithChildren<{ command: str
const Navbar = observer(() => {
const { query } = useKBar()

const noServer = !connectionModelStore.isAnyServerConnected
const noServer = !connectionStore.isAnyServerConnected

const handlePwaUpdate = () => {
settingStore.getUpdateServiceWorker()?.()
Expand Down
14 changes: 7 additions & 7 deletions src/components/OmniBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { chatStore } from '~/core/ChatStore'
import type { IMessageModel } from '~/core/MessageModel'

import DaisyUiThemeProvider from '~/containers/DaisyUiThemeProvider'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import { connectionStore } from '~/core/connection/ConnectionStore'

const isSelected = ({ parent, id }: ActionImpl) => {
if (parent === 'theme') {
Expand All @@ -35,8 +35,8 @@ const isSelected = ({ parent, id }: ActionImpl) => {
}

if (parent === 'model') {
console.log('model: ', id, connectionModelStore.selectedModelName)
return id === connectionModelStore.selectedModelName
console.log('model: ', id, connectionStore.selectedModelName)
return id === connectionStore.selectedModelName
}

if (parent === 'chat') {
Expand Down Expand Up @@ -167,10 +167,10 @@ const useRegisterModelActions = () => {
keywords: 'refresh',
priority: Priority.LOW,
parent: 'refresh_models',
perform: connectionModelStore.refreshModels,
perform: connectionStore.refreshModels,
})

for (const connection of connectionModelStore.connections) {
for (const connection of connectionStore.connections) {
if (!connection.enabled) continue

const typeAndLabel = `${connection.type} ${connection.label}`
Expand All @@ -191,7 +191,7 @@ const useRegisterModelActions = () => {
keywords: `${model.modelName} model ` + typeAndLabel,
section: connection.label + ' Models',
parent: 'model',
perform: () => connectionModelStore.dataStore.setSelectedModel(model, connection.id),
perform: () => connectionStore.dataStore.setSelectedModel(model, connection.id),
})
})
}
Expand Down Expand Up @@ -412,7 +412,7 @@ const OmniBar = () => {
keywords: 'refresh',
section: 'Actions',
priority: Priority.LOW,
perform: connectionModelStore.refreshModels,
perform: connectionStore.refreshModels,
}),
createAction({
name: 'Open settings',
Expand Down
8 changes: 4 additions & 4 deletions src/core/ChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { incomingMessageStore } from '~/core/IncomingMessageStore'
import base64EncodeImage from '~/utils/base64EncodeImage'
import CachedStorage from '~/utils/CachedStorage'

import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import BaseApi from '~/core/connections/api/BaseApi'
import { connectionStore } from '~/core/connection/ConnectionStore'
import BaseApi from '~/core/connection/api/BaseApi'

export const ChatModel = types
.model({
Expand Down Expand Up @@ -231,8 +231,8 @@ export const ChatModel = types

const incomingMessage = MessageModel.create({
fromBot: true,
botName: connectionModelStore.selectedModelName,
modelType: connectionModelStore.selectedConnection?.type,
botName: connectionStore.selectedModelName,
modelType: connectionStore.selectedConnection?.type,
uniqId,
content: '',
})
Expand Down
14 changes: 7 additions & 7 deletions src/core/IncomingMessageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { IMessageModel, MessageModel } from '~/core/MessageModel'
import { toastStore } from '~/core/ToastStore'
import { IChatModel } from '~/core/ChatModel'

import BaseApi from '~/core/connections/api/BaseApi'
import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import BaseApi from '~/core/connection/api/BaseApi'
import { connectionStore } from '~/core/connection/ConnectionStore'

const IncomingMessageAbortedModel = types.model({
id: types.identifier,
Expand Down Expand Up @@ -79,7 +79,7 @@ export const IncomingMessageStore = types

const messageToEdit = incomingMessage.selectedVariation

messageToEdit.setModelName(connectionModelStore.selectedModelName!)
messageToEdit.setModelName(connectionStore.selectedModelName!)

console.log(prompt)

Expand Down Expand Up @@ -108,17 +108,17 @@ export const IncomingMessageStore = types

self.messageById.put(messageToEdit)

const connection = connectionModelStore.selectedConnection
const connection = connectionStore.selectedConnection

if (!connection) throw 'Unknown server'

if (connectionModelStore.isImageGenerationMode) {
if (connectionStore.isImageGenerationMode) {
return this.generateImage(chat, incomingMessage, connection.api)
}

const api: BaseApi | undefined = connection.api

messageToEdit.setModelName(connectionModelStore.selectedModelName!)
messageToEdit.setModelName(connectionStore.selectedModelName!)

await this.handleIncomingMessage(incomingMessage, async () => {
for await (const contentChunk of api.generateChat(
Expand Down Expand Up @@ -147,7 +147,7 @@ export const IncomingMessageStore = types
messageToEdit.setError(error)

// make sure the server is still connected
connectionModelStore.selectedConnection?.fetchLmModels()
connectionStore.selectedConnection?.fetchLmModels()
}
} finally {
if (shouldDeleteMessage) {
Expand Down
20 changes: 10 additions & 10 deletions src/core/SettingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import _ from 'lodash'

import { type SettingPanelOptionsType } from '~/features/settings/settingsPanels'

import { connectionModelStore } from '~/core/connections/ConnectionModelStore'
import LmsServerConnection from '~/core/connections/servers/LmsServerConnection'
import A1111ServerConnection from '~/core/connections/servers/A1111ServerConnection'
import OllamaServerConnection from '~/core/connections/servers/OllamaServerConnection'
import { connectionStore } from '~/core/connection/ConnectionStore'
import LmsConnectionViewModel from '~/core/connection/viewModels/LmsConnectionViewModel'
import A1111ConnectionViewModel from '~/core/connection/viewModels/A1111ConnectionViewModel'
import OllamaConnectionViewModel from '~/core/connection/viewModels/OllamaConnectionViewModel'

import { VoiceModel } from '~/core/VoiceModel'

Expand Down Expand Up @@ -105,7 +105,7 @@ const migrateV2 = (settings: Record<string, unknown>) => {
console.log('running v2 migration')

if (settings.lmsEnabled) {
const lmsSnapshot = _.cloneDeep(LmsServerConnection.getSnapshot())
const lmsSnapshot = _.cloneDeep(LmsConnectionViewModel.getSnapshot())
lmsSnapshot.host = (settings.lmsHost as string) || lmsSnapshot.host
;[['temperature', 'lmsTemperature']].forEach(([field, oldField]) => {
const parameterIndex = _.findIndex(lmsSnapshot.parameters, { field })
Expand All @@ -115,11 +115,11 @@ const migrateV2 = (settings: Record<string, unknown>) => {
}
})

connectionModelStore.dataStore.addConnection('LMS', lmsSnapshot)
connectionStore.dataStore.addConnection('LMS', lmsSnapshot)
}

if (settings.a1111Enabled) {
const a1111Snapshot = _.cloneDeep(A1111ServerConnection.getSnapshot())
const a1111Snapshot = _.cloneDeep(A1111ConnectionViewModel.getSnapshot())
a1111Snapshot.host = (settings.a1111Host as string) || a1111Snapshot.host
;[
['width', 'a1111Width'],
Expand All @@ -134,12 +134,12 @@ const migrateV2 = (settings: Record<string, unknown>) => {
}
})

connectionModelStore.dataStore.addConnection('A1111', a1111Snapshot)
connectionStore.dataStore.addConnection('A1111', a1111Snapshot)
}

// it was enabled if it was true or undefined
if (settings.ollamaEnabled !== false) {
const ollamaSnapshot = _.cloneDeep(OllamaServerConnection.getSnapshot())
const ollamaSnapshot = _.cloneDeep(OllamaConnectionViewModel.getSnapshot())
ollamaSnapshot.host = (settings.ollamaHost as string) || ollamaSnapshot.host
;[
['keep_alive', 'ollamaKeepAliveTime'],
Expand All @@ -152,7 +152,7 @@ const migrateV2 = (settings: Record<string, unknown>) => {
}
})

connectionModelStore.dataStore.addConnection('Ollama', ollamaSnapshot)
connectionStore.dataStore.addConnection('Ollama', ollamaSnapshot)
}

delete settings.ollamaEnabled
Expand Down
File renamed without changes.
Loading

0 comments on commit 36aca9d

Please sign in to comment.