i18n notifications and details

This commit is contained in:
josc146 2023-05-18 21:19:13 +08:00
parent 5078a884b0
commit 934f7b15e8
7 changed files with 32 additions and 16 deletions

View File

@ -35,7 +35,8 @@ def switch_model(body: SwitchModelBody, response: Response):
tokens_path=f"{pathlib.Path(__file__).parent.parent.resolve()}/20B_tokenizer.json",
),
)
except Exception:
except Exception as e:
print(e)
global_var.set(global_var.Model_Status, global_var.ModelStatus.Offline)
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, "failed to load")

View File

@ -87,7 +87,7 @@ const App: FC = observer(() => {
</div>
<ToastContainer
style={{
width: '250px'
width: '350px'
}}
position="top-center"
autoClose={4000}

View File

@ -51,5 +51,13 @@
"Last updated": "上次更新",
"Desc": "描述",
"Size": "文件大小",
"File": "文件"
"File": "文件",
"Config Saved": "配置已保存",
"Downloading": "正在下载",
"Loading Model": "正在读取模型",
"Startup Completed": "启动完成",
"Failed to switch model": "切换模型失败",
"Start Converting": "开始转换",
"Convert Success": "转换成功",
"Convert Failed": "转换失败"
}

View File

@ -1,14 +1,17 @@
import commonStore, {ModelStatus} from '../stores/commonStore';
import commonStore from '../stores/commonStore';
export const readRoot = async () => {
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
return fetch(`http://127.0.0.1:${port}`);
};
export const exit = async () => {
commonStore.setModelStatus(ModelStatus.Offline);
export const exit = async (timeout?: number) => {
const controller = new AbortController();
if (timeout)
setTimeout(() => controller.abort(), timeout);
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
return fetch(`http://127.0.0.1:${port}/exit`, {method: 'POST'});
return fetch(`http://127.0.0.1:${port}/exit`, {method: 'POST', signal: controller.signal});
};
export const switchModel = async (body: any) => {

View File

@ -8,6 +8,7 @@ import {toast} from 'react-toastify';
import manifest from '../../../manifest.json';
import {getStrategy} from '../utils';
import {useTranslation} from 'react-i18next';
import {t} from 'i18next';
const mainButtonText = {
[ModelStatus.Offline]: 'Run',
@ -22,6 +23,8 @@ const onClickMainButton = async () => {
if (commonStore.modelStatus === ModelStatus.Offline) {
commonStore.setModelStatus(ModelStatus.Starting);
await exit(1000).catch(() => {
});
StartServer(port);
let timeoutCount = 6;
@ -33,7 +36,7 @@ const onClickMainButton = async () => {
clearInterval(intervalId);
commonStore.setModelStatus(ModelStatus.Loading);
loading = true;
toast('Loading Model', {type: 'info'});
toast(t('Loading Model'), {type: 'info'});
updateConfig({
max_tokens: modelConfig.apiParameters.maxResponseToken,
temperature: modelConfig.apiParameters.temperature,
@ -47,12 +50,12 @@ const onClickMainButton = async () => {
}).then((r) => {
if (r.ok) {
commonStore.setModelStatus(ModelStatus.Working);
toast('Startup Completed', {type: 'success'});
toast(t('Startup Completed'), {type: 'success'});
} else if (r.status === 304) {
toast('Loading Model', {type: 'info'});
toast(t('Loading Model'), {type: 'info'});
} else {
commonStore.setModelStatus(ModelStatus.Offline);
toast('Failed to switch model', {type: 'error'});
toast(t('Failed to switch model'), {type: 'error'});
}
});
}
@ -66,6 +69,7 @@ const onClickMainButton = async () => {
timeoutCount--;
}, 1000);
} else {
commonStore.setModelStatus(ModelStatus.Offline);
exit();
}
};

View File

@ -64,7 +64,7 @@ export const Configs: FC = observer(() => {
presence_penalty: selectedConfig.apiParameters.presencePenalty,
frequency_penalty: selectedConfig.apiParameters.frequencyPenalty
});
toast('Config Saved', {autoClose: 300, type: 'success'});
toast(t('Config Saved'), {autoClose: 300, type: 'success'});
};
return (
@ -182,12 +182,12 @@ export const Configs: FC = observer(() => {
const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`;
const strategy = getStrategy(selectedConfig);
const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-');
toast('Start Converting', {autoClose: 1000, type: 'info'});
toast(t('Start Converting'), {autoClose: 1000, type: 'info'});
ConvertModel(modelPath, strategy, newModelPath).then(() => {
toast(`Convert Success - ${newModelPath}`, {type: 'success'});
toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'});
refreshLocalModels({models: commonStore.modelSourceList});
}).catch(e => {
toast(`Convert Failed - ${e}`, {type: 'error'});
toast(`${t('Convert Failed')} - ${e}`, {type: 'error'});
});
}}/>
<Labeled label={t('Device')} content={

View File

@ -129,7 +129,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
}
{item.downloadUrl && !item.isLocal &&
<ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular/>} onClick={() => {
toast(`Downloading ${item.name}`);
toast(`${t('Downloading')} ${item.name}`);
DownloadFile(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
}}/>}
{item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular/>} onClick={() => {