reload buffer (#3665)

* reload buffer

* reload buffer

* tts selector
This commit is contained in:
Archer 2025-01-25 13:12:21 +08:00 committed by GitHub
parent d2948d7e57
commit 92105e9a0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 38 additions and 17 deletions

View File

@ -39,3 +39,13 @@ export const updateFastGPTConfigBuffer = async () => {
global.systemInitBufferId = res.createTime.getTime().toString();
};
export const reloadFastGPTConfigBuffer = async () => {
const res = await MongoSystemConfigs.findOne({
type: SystemConfigsTypeEnum.fastgpt
}).sort({
createTime: -1
});
if (!res) return;
global.systemInitBufferId = res.createTime.getTime().toString();
};

View File

@ -13,6 +13,11 @@ import {
import { debounce } from 'lodash';
import { ModelProviderType } from '@fastgpt/global/core/ai/provider';
import { findModelFromAlldata } from '../model';
import {
reloadFastGPTConfigBuffer,
updateFastGPTConfigBuffer
} from '../../../common/system/config/controller';
import { delay } from '@fastgpt/global/common/system/utils';
/*
TODO: 分优先级读取
@ -170,8 +175,21 @@ export const watchSystemModelUpdate = () => {
'change',
debounce(async () => {
try {
// Main node will reload twice
await loadSystemModels(true);
// All node reaload buffer
await reloadFastGPTConfigBuffer();
} catch (error) {}
}, 500)
);
};
// 更新完模型后,需要重载缓存
export const updatedReloadSystemModel = async () => {
// 1. 更新模型(所有节点都会触发)
await loadSystemModels(true);
// 2. 更新缓存(仅主节点触发)
await updateFastGPTConfigBuffer();
// 3. 延迟1秒等待其他节点刷新
await delay(1000);
};

View File

@ -70,7 +70,7 @@ const TTSSelect = ({
const provider = selectorList.find((item) => item.value === formatValue[0]) || selectorList[0];
const voice = provider.children.find((item) => item.value === formatValue[1]);
return (
<Box minW={'150px'} maxW={'220px'} className="textEllipsis">
<Box maxW={'220px'} className="textEllipsis">
{voice ? (
<Flex alignItems={'center'}>
<Box>{provider.label}</Box>
@ -141,7 +141,7 @@ const TTSSelect = ({
<FormLabel>{t('common:core.app.tts.Speech model')}</FormLabel>
<MultipleRowSelect
rowMinWidth="160px"
label={formLabel}
label={<Box minW={'150px'}>{formLabel}</Box>}
value={formatValue}
list={selectorList}
onSelect={onclickChange}

View File

@ -4,7 +4,7 @@ import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
import { findModelFromAlldata } from '@fastgpt/service/core/ai/model';
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
import { loadSystemModels, updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
export type deleteQuery = {
model: string;
@ -34,8 +34,7 @@ async function handler(
await MongoSystemModel.deleteOne({ model });
await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();
return {};
}

View File

@ -2,10 +2,8 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
import { NextAPI } from '@/service/middleware/entry';
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
import { delay } from '@fastgpt/global/common/system/utils';
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
import { findModelFromAlldata } from '@fastgpt/service/core/ai/model';
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
import { updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
export type updateQuery = {};
@ -58,8 +56,7 @@ async function handler(
}
);
await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();
return {};
}

View File

@ -2,7 +2,7 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
import { NextAPI } from '@/service/middleware/entry';
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
import { loadSystemModels, updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
@ -67,8 +67,7 @@ async function handler(
}
});
await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();
return {};
}

View File

@ -4,8 +4,7 @@ import { SystemModelSchemaType } from '@fastgpt/service/core/ai/type';
import { authSystemAdmin } from '@fastgpt/service/support/permission/user/auth';
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
import { MongoSystemModel } from '@fastgpt/service/core/ai/config/schema';
import { updateFastGPTConfigBuffer } from '@fastgpt/service/common/system/config/controller';
import { loadSystemModels } from '@fastgpt/service/core/ai/config/utils';
import { updatedReloadSystemModel } from '@fastgpt/service/core/ai/config/utils';
export type updateWithJsonQuery = {};
@ -55,8 +54,7 @@ async function handler(
}
});
await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();
return {};
}