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