fix startup status detect
This commit is contained in:
parent
5729d9fc62
commit
6f629dbc55
@ -43,8 +43,8 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
const navigate = useNavigate();
|
||||
|
||||
const onClickMainButton = async () => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Starting });
|
||||
if (commonStore.status.status === ModelStatus.Offline) {
|
||||
commonStore.setStatus({ status: ModelStatus.Starting });
|
||||
|
||||
const modelConfig = commonStore.getCurrentModelConfig();
|
||||
let modelName = '';
|
||||
@ -54,7 +54,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
modelPath = `./${manifest.localModelDir}/${modelName}`;
|
||||
} else {
|
||||
toast(t('Model Config Exception'), { type: 'error' });
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
}
|
||||
});
|
||||
if (depErrorMsg) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
commonStore.setDepComplete(true);
|
||||
@ -102,7 +102,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
}
|
||||
});
|
||||
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
if (status)
|
||||
commonStore.setStatus(status);
|
||||
});
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Loading });
|
||||
commonStore.setStatus({ status: ModelStatus.Loading });
|
||||
toast(t('Loading Model'), { type: 'info' });
|
||||
updateConfig({
|
||||
max_tokens: modelConfig.apiParameters.maxResponseToken,
|
||||
@ -161,51 +161,51 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
customCuda: customCudaFile !== ''
|
||||
}).then((r) => {
|
||||
if (r.ok) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Working });
|
||||
commonStore.setStatus({ status: ModelStatus.Working });
|
||||
toastWithButton(t('Startup Completed'), t('Chat'), () => {
|
||||
navigate({ pathname: '/chat' });
|
||||
}, { type: 'success', autoClose: 3000 });
|
||||
} else if (r.status === 304) {
|
||||
toast(t('Loading Model'), { type: 'info' });
|
||||
} else {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
toast(t('Failed to switch model'), { type: 'error' });
|
||||
}
|
||||
}).catch(() => {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
toast(t('Failed to switch model'), { type: 'error' });
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
if (timeoutCount <= 0) {
|
||||
clearInterval(intervalId);
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
}
|
||||
});
|
||||
|
||||
timeoutCount--;
|
||||
}, 1000);
|
||||
} else {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
exit();
|
||||
}
|
||||
};
|
||||
|
||||
const onClick = async (e: any) => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline)
|
||||
if (commonStore.status.status === ModelStatus.Offline)
|
||||
await onClickRun?.(e);
|
||||
await onClickMainButton();
|
||||
};
|
||||
|
||||
return (iconMode ?
|
||||
<ToolTipButton disabled={commonStore.status.modelStatus === ModelStatus.Starting}
|
||||
icon={iconModeButtonIcon[commonStore.status.modelStatus]}
|
||||
desc={t(mainButtonText[commonStore.status.modelStatus])}
|
||||
<ToolTipButton disabled={commonStore.status.status === ModelStatus.Starting}
|
||||
icon={iconModeButtonIcon[commonStore.status.status]}
|
||||
desc={t(mainButtonText[commonStore.status.status])}
|
||||
size="small" onClick={onClick} />
|
||||
:
|
||||
<Button disabled={commonStore.status.modelStatus === ModelStatus.Starting} appearance="primary" size="large"
|
||||
<Button disabled={commonStore.status.status === ModelStatus.Starting} appearance="primary" size="large"
|
||||
onClick={onClick}>
|
||||
{t(mainButtonText[commonStore.status.modelStatus])}
|
||||
{t(mainButtonText[commonStore.status.status])}
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
|
@ -29,8 +29,8 @@ export const WorkHeader: FC = observer(() => {
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex items-center gap-2">
|
||||
<PresenceBadge status={badgeStatus[commonStore.status.modelStatus]} />
|
||||
<Text size={100}>{t('Model Status') + ': ' + t(statusText[commonStore.status.modelStatus])}</Text>
|
||||
<PresenceBadge status={badgeStatus[commonStore.status.status]} />
|
||||
<Text size={100}>{t('Model Status') + ': ' + t(statusText[commonStore.status.status])}</Text>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ConfigSelector size="small" />
|
||||
|
@ -93,7 +93,7 @@ const ChatPanel: FC = observer(() => {
|
||||
e.stopPropagation();
|
||||
if (e.type === 'click' || (e.keyCode === 13 && !e.shiftKey)) {
|
||||
e.preventDefault();
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
if (commonStore.status.status === ModelStatus.Offline) {
|
||||
toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' });
|
||||
return;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
};
|
||||
|
||||
const onSubmit = (prompt: string) => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
if (commonStore.status.status === ModelStatus.Offline) {
|
||||
toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' });
|
||||
commonStore.setCompletionGenerating(false);
|
||||
return;
|
||||
|
@ -33,7 +33,7 @@ export async function startup() {
|
||||
if (commonStore.settings.autoUpdatesCheck) // depends on config settings
|
||||
checkUpdate();
|
||||
|
||||
getStatus(500).then(status => { // depends on config api port
|
||||
getStatus(1000).then(status => { // depends on config api port
|
||||
if (status)
|
||||
commonStore.setStatus(status);
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ export enum ModelStatus {
|
||||
}
|
||||
|
||||
export type Status = {
|
||||
modelStatus: ModelStatus;
|
||||
status: ModelStatus;
|
||||
pid: number;
|
||||
device_name: string;
|
||||
}
|
||||
@ -28,7 +28,7 @@ export type Status = {
|
||||
class CommonStore {
|
||||
// global
|
||||
status: Status = {
|
||||
modelStatus: ModelStatus.Offline,
|
||||
status: ModelStatus.Offline,
|
||||
pid: 0,
|
||||
device_name: 'CPU'
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user