diff --git a/web/containers/ErrorMessage/index.tsx b/web/containers/ErrorMessage/index.tsx index da866714e5..a119d31ef9 100644 --- a/web/containers/ErrorMessage/index.tsx +++ b/web/containers/ErrorMessage/index.tsx @@ -23,7 +23,13 @@ import { mainViewStateAtom } from '@/helpers/atoms/App.atom' import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom' import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom' -const ErrorMessage = ({ message }: { message: ThreadMessage }) => { +const ErrorMessage = ({ + message, + errorComponent, +}: { + message?: ThreadMessage + errorComponent?: React.ReactNode +}) => { const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom) const setMainState = useSetAtom(mainViewStateAtom) const setSelectedSettingScreen = useSetAtom(selectedSettingAtom) @@ -50,7 +56,7 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { const getErrorTitle = () => { const engine = getEngine() - switch (message.metadata?.error_code) { + switch (message?.metadata?.error_code) { case ErrorCode.InvalidApiKey: case ErrorCode.AuthenticationError: return ( @@ -77,7 +83,7 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { data-testid="passthrough-error-message" className="first-letter:uppercase" > - {message.content[0]?.text?.value === 'Failed to fetch' && + {message?.content[0]?.text?.value === 'Failed to fetch' && engine && engine?.name !== InferenceEngine.cortex_llamacpp ? ( @@ -103,7 +109,7 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
@@ -147,7 +153,7 @@ const ErrorMessage = ({ message }: { message: ThreadMessage }) => { className="font-serif text-xs leading-relaxed text-[hsla(var(--text-secondary))]" ref={errorDivRef} > - {getErrorTitle()} + {errorComponent ? errorComponent : getErrorTitle()}
diff --git a/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx b/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx index 3a887e8eab..ed0e6bcfc1 100644 --- a/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/LoadModelError/index.tsx @@ -1,6 +1,7 @@ import { EngineManager, InferenceEngine } from '@janhq/core' import { useAtomValue, useSetAtom } from 'jotai' +import ErrorMessage from '@/containers/ErrorMessage' import ModalTroubleShooting, { modalTroubleShootingAtom, } from '@/containers/ModalTroubleShoot' @@ -20,62 +21,43 @@ const LoadModelError = () => { const setSelectedSettingScreen = useSetAtom(selectedSettingAtom) const activeAssistant = useAtomValue(activeAssistantAtom) - const ErrorMessage = () => { - if ( - typeof loadModelError?.includes === 'function' && - loadModelError.includes('EXTENSION_IS_NOT_INSTALLED') - ) { - return ( -

- Model is currently unavailable. Please switch to a different model or - install the{' '} - { - setMainState(MainViewState.Settings) - if (activeAssistant?.model.engine) { - const engine = EngineManager.instance().get( - InferenceEngine.cortex - ) - engine?.name && setSelectedSettingScreen(engine.name) - } - }} - > - {loadModelError.split('::')[1] ?? ''} - {' '} - to continue using it. -

- ) - } else { - return ( -
- {loadModelError && ( -

{loadModelError}

+ return ( + + {typeof loadModelError?.includes === 'function' && + loadModelError.includes('EXTENSION_IS_NOT_INSTALLED') ? ( + <> +

+ Model is currently unavailable. Please switch to a different + model or install the{' '} + { + setMainState(MainViewState.Settings) + if (activeAssistant?.model.engine) { + const engine = EngineManager.instance().get( + InferenceEngine.cortex + ) + engine?.name && setSelectedSettingScreen(engine.name) + } + }} + > + {loadModelError.split('::')[1] ?? ''} + {' '} + to continue using it. +

+ + ) : ( + <> + {loadModelError && ( +

{loadModelError}

+ )} + )} -

- {`Something's wrong.`} Access  - setModalTroubleShooting(true)} - > - troubleshooting assistance - -  now. -

- ) - } - } - - return ( -
-
-

- -

- -
-
+ } + /> ) } export default LoadModelError