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

reload buffer #3665

Merged
merged 3 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions packages/service/common/system/config/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
18 changes: 18 additions & 0 deletions packages/service/core/ai/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 分优先级读取:
Expand Down Expand Up @@ -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);
};
4 changes: 2 additions & 2 deletions projects/app/src/components/core/app/TTSSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 2 additions & 3 deletions projects/app/src/pages/api/core/ai/model/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,8 +34,7 @@ async function handler(

await MongoSystemModel.deleteOne({ model });

await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();

return {};
}
Expand Down
7 changes: 2 additions & 5 deletions projects/app/src/pages/api/core/ai/model/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -58,8 +56,7 @@ async function handler(
}
);

await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();

return {};
}
Expand Down
5 changes: 2 additions & 3 deletions projects/app/src/pages/api/core/ai/model/updateDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -67,8 +67,7 @@ async function handler(
}
});

await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();

return {};
}
Expand Down
6 changes: 2 additions & 4 deletions projects/app/src/pages/api/core/ai/model/updateWithJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -55,8 +54,7 @@ async function handler(
}
});

await loadSystemModels(true);
await updateFastGPTConfigBuffer();
await updatedReloadSystemModel();

return {};
}
Expand Down
Loading