Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: better error handing for remote models when there's no internet connection #4252

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 55 additions & 32 deletions web/containers/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import { MainViewState } from '@/constants/screens'

import { isLocalEngine } from '@/utils/modelEngine'

import { mainViewStateAtom } from '@/helpers/atoms/App.atom'

import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom'
Expand All @@ -25,64 +27,85 @@
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
const activeThread = useAtomValue(activeThreadAtom)

const defaultDesc = () => {
return (
<>
<p>
{`Something's wrong.`} Access&nbsp;
<span
className="cursor-pointer text-[hsla(var(--app-link))] underline"
onClick={() => setModalTroubleShooting(true)}
>
troubleshooting assistance
</span>
&nbsp;now.
</p>
<ModalTroubleShooting />
</>
)
}

const getEngine = () => {
const engineName = activeThread?.assistants?.[0]?.model?.engine
return engineName ? EngineManager.instance().get(engineName) : null
}

const getErrorTitle = () => {
const engine = getEngine()

switch (message.error_code) {
case ErrorCode.InvalidApiKey:
case ErrorCode.AuthenticationError:
return (
<span data-testid="invalid-API-key-error">
Invalid API key. Please check your API key from{' '}
<button
className="font-medium text-[hsla(var(--app-link))] underline"
onClick={() => {
setMainState(MainViewState.Settings)

if (activeThread?.assistants[0]?.model.engine) {
const engine = EngineManager.instance().get(
activeThread.assistants[0].model.engine
)
<>
<span data-testid="invalid-API-key-error">
Invalid API key. Please check your API key from{' '}
<button
className="font-medium text-[hsla(var(--app-link))] underline"
onClick={() => {
setMainState(MainViewState.Settings)
engine?.name && setSelectedSettingScreen(engine.name)

Check warning on line 67 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

66-67 lines are not covered with tests
}
}}
>
Settings
</button>{' '}
and try again.
</span>
}}
>
Settings
</button>{' '}
and try again.
</span>
{defaultDesc()}
</>
)
default:
return (
<p
data-testid="passthrough-error-message"
className="first-letter:uppercase"
>
{message.content[0]?.text?.value && (
<AutoLink text={message.content[0].text.value} />
{message.content[0]?.text?.value === 'Failed to fetch' &&
engine &&
!isLocalEngine(String(engine?.name)) ? (
<span>
No internet connection. <br /> Switch to an on-device model or
check connection.
</span>
) : (
<>
<AutoLink text={message.content[0].text.value} />
{defaultDesc()}
</>
)}
</p>
)
}
}

return (
<div className="mx-auto mt-10 max-w-[700px]">
<div className="mx-auto my-6 max-w-[700px]">
{message.status === MessageStatus.Error && (
<div
key={message.id}
className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]"
>
{getErrorTitle()}
<p>
{`Something's wrong.`} Access&nbsp;
<span
className="cursor-pointer text-[hsla(var(--app-link))] underline"
onClick={() => setModalTroubleShooting(true)}
>
troubleshooting assistance
</span>
&nbsp;now.
</p>
<ModalTroubleShooting />
</div>
)}
</div>
Expand Down
Loading