fix: inconsistent error handling
This commit is contained in:
parent
c501641c91
commit
8bd0f3da21
@ -26,15 +26,13 @@ export const stateModelAtom = atom<ModelState>({
|
|||||||
model: undefined,
|
model: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
const pendingModelLoadAtom = atom<boolean>(false)
|
|
||||||
|
|
||||||
export function useActiveModel() {
|
export function useActiveModel() {
|
||||||
const [activeModel, setActiveModel] = useAtom(activeModelAtom)
|
const [activeModel, setActiveModel] = useAtom(activeModelAtom)
|
||||||
const activeThread = useAtomValue(activeThreadAtom)
|
const activeThread = useAtomValue(activeThreadAtom)
|
||||||
const [stateModel, setStateModel] = useAtom(stateModelAtom)
|
const [stateModel, setStateModel] = useAtom(stateModelAtom)
|
||||||
const downloadedModels = useAtomValue(downloadedModelsAtom)
|
const downloadedModels = useAtomValue(downloadedModelsAtom)
|
||||||
const setLoadModelError = useSetAtom(loadModelErrorAtom)
|
const setLoadModelError = useSetAtom(loadModelErrorAtom)
|
||||||
const [pendingModelLoad, setPendingModelLoad] = useAtom(pendingModelLoadAtom)
|
const pendingModelLoad = useRef(false)
|
||||||
const isVulkanEnabled = useAtomValue(vulkanEnabledAtom)
|
const isVulkanEnabled = useAtomValue(vulkanEnabledAtom)
|
||||||
|
|
||||||
const downloadedModelsRef = useRef<Model[]>([])
|
const downloadedModelsRef = useRef<Model[]>([])
|
||||||
@ -55,7 +53,7 @@ export function useActiveModel() {
|
|||||||
if (activeModel) {
|
if (activeModel) {
|
||||||
await stopModel(activeModel)
|
await stopModel(activeModel)
|
||||||
}
|
}
|
||||||
setPendingModelLoad(true)
|
pendingModelLoad.current = true
|
||||||
|
|
||||||
let model = downloadedModelsRef?.current.find((e) => e.id === modelId)
|
let model = downloadedModelsRef?.current.find((e) => e.id === modelId)
|
||||||
|
|
||||||
@ -120,16 +118,16 @@ export function useActiveModel() {
|
|||||||
undefined,
|
undefined,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (!pendingModelLoad && abortable) {
|
if (!pendingModelLoad.current && abortable) {
|
||||||
return Promise.reject(new Error('aborted'))
|
return Promise.reject(new Error('aborted'))
|
||||||
}
|
}
|
||||||
|
|
||||||
toaster({
|
toaster({
|
||||||
title: 'Failed!',
|
title: 'Failed!',
|
||||||
description: `Model ${model.id} failed to start.`,
|
description: `Model ${model.id} failed to start. ${error.message ?? ''}`,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
})
|
})
|
||||||
setLoadModelError(error)
|
setLoadModelError(error.message ?? error)
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -147,16 +145,10 @@ export function useActiveModel() {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
setActiveModel(undefined)
|
setActiveModel(undefined)
|
||||||
setStateModel({ state: 'start', loading: false, model: undefined })
|
setStateModel({ state: 'start', loading: false, model: undefined })
|
||||||
setPendingModelLoad(false)
|
pendingModelLoad.current = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[
|
[activeModel, setStateModel, setActiveModel, stateModel]
|
||||||
activeModel,
|
|
||||||
setStateModel,
|
|
||||||
setActiveModel,
|
|
||||||
setPendingModelLoad,
|
|
||||||
stateModel,
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const stopInference = useCallback(async () => {
|
const stopInference = useCallback(async () => {
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import { MessageRequestBuilder } from '@/utils/messageRequestBuilder'
|
|||||||
|
|
||||||
import { ThreadMessageBuilder } from '@/utils/threadMessageBuilder'
|
import { ThreadMessageBuilder } from '@/utils/threadMessageBuilder'
|
||||||
|
|
||||||
import { loadModelErrorAtom, useActiveModel } from './useActiveModel'
|
import { useActiveModel } from './useActiveModel'
|
||||||
|
|
||||||
import { extensionManager } from '@/extension/ExtensionManager'
|
import { extensionManager } from '@/extension/ExtensionManager'
|
||||||
import {
|
import {
|
||||||
@ -60,10 +60,8 @@ export default function useSendChatMessage() {
|
|||||||
const currentMessages = useAtomValue(getCurrentChatMessagesAtom)
|
const currentMessages = useAtomValue(getCurrentChatMessagesAtom)
|
||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
const selectedModel = useAtomValue(selectedModelAtom)
|
||||||
const { activeModel, startModel } = useActiveModel()
|
const { activeModel, startModel } = useActiveModel()
|
||||||
const loadModelFailed = useAtomValue(loadModelErrorAtom)
|
|
||||||
|
|
||||||
const modelRef = useRef<Model | undefined>()
|
const modelRef = useRef<Model | undefined>()
|
||||||
const loadModelFailedRef = useRef<string | undefined>()
|
|
||||||
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
|
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
|
||||||
const engineParamsUpdate = useAtomValue(engineParamsUpdateAtom)
|
const engineParamsUpdate = useAtomValue(engineParamsUpdateAtom)
|
||||||
|
|
||||||
@ -80,10 +78,6 @@ export default function useSendChatMessage() {
|
|||||||
modelRef.current = activeModel
|
modelRef.current = activeModel
|
||||||
}, [activeModel])
|
}, [activeModel])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadModelFailedRef.current = loadModelFailed
|
|
||||||
}, [loadModelFailed])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
activeThreadRef.current = activeThread
|
activeThreadRef.current = activeThread
|
||||||
}, [activeThread])
|
}, [activeThread])
|
||||||
|
|||||||
@ -20,23 +20,8 @@ const LoadModelError = () => {
|
|||||||
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
|
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
|
||||||
const activeThread = useAtomValue(activeThreadAtom)
|
const activeThread = useAtomValue(activeThreadAtom)
|
||||||
|
|
||||||
const PORT_NOT_AVAILABLE = 'PORT_NOT_AVAILABLE'
|
|
||||||
|
|
||||||
const ErrorMessage = () => {
|
const ErrorMessage = () => {
|
||||||
if (loadModelError === PORT_NOT_AVAILABLE) {
|
if (
|
||||||
return (
|
|
||||||
<p>
|
|
||||||
Port 3928 is currently unavailable. Check for conflicting apps, or
|
|
||||||
access
|
|
||||||
<span
|
|
||||||
className="cursor-pointer text-[hsla(var(--app-link))]"
|
|
||||||
onClick={() => setModalTroubleShooting(true)}
|
|
||||||
>
|
|
||||||
troubleshooting assistance
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
)
|
|
||||||
} else if (
|
|
||||||
typeof loadModelError?.includes === 'function' &&
|
typeof loadModelError?.includes === 'function' &&
|
||||||
loadModelError.includes('EXTENSION_IS_NOT_INSTALLED')
|
loadModelError.includes('EXTENSION_IS_NOT_INSTALLED')
|
||||||
) {
|
) {
|
||||||
@ -63,10 +48,10 @@ const LoadModelError = () => {
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]">
|
||||||
Apologies, {`Something's wrong.`}.
|
{loadModelError && <p>{loadModelError}</p>}
|
||||||
<p>
|
<p>
|
||||||
Access
|
{`Something's wrong.`} Access
|
||||||
<span
|
<span
|
||||||
className="cursor-pointer text-[hsla(var(--app-link))]"
|
className="cursor-pointer text-[hsla(var(--app-link))]"
|
||||||
onClick={() => setModalTroubleShooting(true)}
|
onClick={() => setModalTroubleShooting(true)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user