mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 03:29:25 +01:00
feat(AI Assistant): remember last model used
This commit is contained in:
parent
e869609680
commit
3795857117
|
|
@ -1,3 +1,3 @@
|
|||
import { KVStoreKey } from "../types/kv_store.js";
|
||||
|
||||
export const SETTINGS_KEYS: KVStoreKey[] = ['chat.suggestionsEnabled', 'ui.hasVisitedEasySetup', 'system.earlyAccess', 'ai.assistantCustomName'];
|
||||
export const SETTINGS_KEYS: KVStoreKey[] = ['chat.suggestionsEnabled', 'chat.lastModel', 'ui.hasVisitedEasySetup', 'system.earlyAccess', 'ai.assistantCustomName'];
|
||||
|
|
@ -10,6 +10,7 @@ import { ChatMessage } from '../../../types/chat'
|
|||
import classNames from '~/lib/classNames'
|
||||
import { IconX } from '@tabler/icons-react'
|
||||
import { DEFAULT_QUERY_REWRITE_MODEL } from '../../../constants/ollama'
|
||||
import { useSystemSetting } from '~/hooks/useSystemSetting'
|
||||
|
||||
interface ChatProps {
|
||||
enabled: boolean
|
||||
|
|
@ -51,6 +52,8 @@ export default function Chat({
|
|||
|
||||
const activeSession = sessions.find((s) => s.id === activeSessionId)
|
||||
|
||||
const { data: lastModelSetting } = useSystemSetting({ key: 'chat.lastModel', enabled })
|
||||
|
||||
const { data: installedModels = [], isLoading: isLoadingModels } = useQuery({
|
||||
queryKey: ['installedModels'],
|
||||
queryFn: () => api.getInstalledModels(),
|
||||
|
|
@ -127,12 +130,24 @@ export default function Chat({
|
|||
},
|
||||
})
|
||||
|
||||
// Set first model as selected by default
|
||||
// Set default model: prefer last used model, fall back to first installed if last model not available
|
||||
useEffect(() => {
|
||||
if (installedModels.length > 0 && !selectedModel) {
|
||||
setSelectedModel(installedModels[0].name)
|
||||
const lastModel = lastModelSetting?.value as string | undefined
|
||||
if (lastModel && installedModels.some((m) => m.name === lastModel)) {
|
||||
setSelectedModel(lastModel)
|
||||
} else {
|
||||
setSelectedModel(installedModels[0].name)
|
||||
}
|
||||
}
|
||||
}, [installedModels, selectedModel])
|
||||
}, [installedModels, selectedModel, lastModelSetting])
|
||||
|
||||
// Persist model selection
|
||||
useEffect(() => {
|
||||
if (selectedModel) {
|
||||
api.updateSetting('chat.lastModel', selectedModel)
|
||||
}
|
||||
}, [selectedModel])
|
||||
|
||||
const handleNewChat = useCallback(() => {
|
||||
// Just clear the active session and messages - don't create a session yet
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
export const KV_STORE_SCHEMA = {
|
||||
'chat.suggestionsEnabled': 'boolean',
|
||||
'chat.lastModel': 'string',
|
||||
'rag.docsEmbedded': 'boolean',
|
||||
'system.updateAvailable': 'boolean',
|
||||
'system.latestVersion': 'string',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user