Skip to content

Commit

Permalink
perf: get init data buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Dec 24, 2024
1 parent 57ce8e6 commit 2c18f1d
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 78 deletions.
Binary file added docSite/assets/imgs/image-55.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/image-56.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/image-57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/image-58.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 19 additions & 9 deletions docSite/content/zh-cn/docs/shopping_cart/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ FastGPT 商业版是基于 FastGPT 开源版的增强版本,增加了一些独
| 应用管理与高级编排 ||||
| 文档知识库 ||||
| 外部使用 ||||
| API 知识库 ||||
| 最大应用数量 | 500 | 无限制 | 由付费套餐决定 |
| 最大知识库数量(单个知识库内容无限制) | 30 | 无限制 | 由付费套餐决定 |
| 自定义版权信息 ||| 设计中 |
| 多租户与支付 ||||
| 团队空间 ||||
| 团队空间 & 权限 ||||
| 应用发布安全配置 ||||
| 内容审核 ||||
| web站点同步 ||||
| 管理后台 ||| 不需要 |
| 主流文档库接入(目前支持:语雀、飞书) ||| |
| 增强训练模式 ||||
| 第三方应用快速接入(飞书、公众号) ||||
| 管理后台 ||| 不需要 |
| SSO 登录(可自定义,也可使用内置:Github、公众号、钉钉、谷歌等) ||| 不需要 |
| 图片知识库 || 设计中 | 设计中 |
| 对话日志运营分析 || 设计中 | 设计中 |
| 完整商业授权 ||||
Expand All @@ -50,8 +53,8 @@ FastGPT 商业版软件根据不同的部署方式,分为 3 类收费模式。
{{< table "table-hover table-striped-columns" >}}
| 部署方式 | 特有服务 | 上线时长 | 标品价格 |
| ---- | ---- | ---- | ---- |
| Sealos全托管 | 1. 有效期内免费升级。<br>2. 免运维服务&数据库。 | 半天 | 5000元起/月(3个月起)<br>或<br>50000元起/年 |
| 自有服务器部署 | 1. 6个版本的升级服务| 14天内 | 具体价格可[联系咨询](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud) |
| Sealos全托管 | 1. 有效期内免费升级。<br>2. 免运维服务&数据库。 | 半天 | 6000元起/月(3个月起)<br>或<br>60000元起/年 |
| 自有服务器部署 | 1. 6个版本免费升级支持| 14天内 | 具体价格可[联系咨询](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud) |
{{< /table >}}

{{% alert icon="🤖 " context="success" %}}
Expand All @@ -62,6 +65,10 @@ FastGPT 商业版软件根据不同的部署方式,分为 3 类收费模式。
- 高可用版适合对外提供在线服务,包含可视化监控、多副本、负载均衡、数据库自动备份等生产环境的基础设施。
{{% /alert %}}

## 联系方式

请填写[咨询问卷](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud),我们会尽快与您联系。


## 技术支持

Expand All @@ -79,9 +86,6 @@ FastGPT 商业版软件根据不同的部署方式,分为 3 类收费模式。

跨版本更新或复杂更新可参考文档自行更新;或付费支持,标准与技术服务费一致。

## 联系方式

请填写[咨询问卷](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud),我们会尽快与您联系。

## QA

Expand All @@ -95,8 +99,14 @@ FastGPT 商业版软件根据不同的部署方式,分为 3 类收费模式。

可以修改开源版部分代码,不支持修改商业版镜像。完整版本=开源版+商业版镜像,所以是可以修改部分内容的。但是如果二开了,后续则需要自己进行代码合并升级。

## Sealos 费用
### Sealos 运行费用

Sealos 云服务属于按量计费,下面是它的价格表:

![](/imgs/sealos_price.jpg)
![alt text](/imgs/image-58.png)

## 管理后台部分截图

| | | |
| ---- | ---- | ---- |
| ![alt text](/imgs/image-55.png) | ![alt text](/imgs/image-56.png) | ![alt text](/imgs/image-57.png) |
12 changes: 10 additions & 2 deletions packages/service/common/system/config/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { FastGPTConfigFileType } from '@fastgpt/global/common/system/types';
import { FastGPTProUrl } from '../constants';

export const getFastGPTConfigFromDB = async () => {
if (!FastGPTProUrl) return {} as FastGPTConfigFileType;
if (!FastGPTProUrl) {
return {
config: {} as FastGPTConfigFileType,
configId: undefined
};
}

const res = await MongoSystemConfigs.findOne({
type: SystemConfigsTypeEnum.fastgpt
Expand All @@ -14,5 +19,8 @@ export const getFastGPTConfigFromDB = async () => {

const config = res?.value || {};

return config as FastGPTConfigFileType;
return {
configId: res ? String(res._id) : undefined,
config: config as FastGPTConfigFileType
};
};
1 change: 0 additions & 1 deletion packages/service/core/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import { PluginTemplateType } from '@fastgpt/global/core/plugin/type.d';
import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type';

declare global {
var communityPluginsV1: PluginTemplateType[];
var communityPlugins: SystemPluginTemplateItemType[];
}
1 change: 1 addition & 0 deletions packages/service/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Worker } from 'worker_threads';
import { TemplateMarketItemType } from '@fastgpt/global/core/workflow/type';

declare global {
var systemInitBufferId: string | undefined;
var systemVersion: string;
var feConfigs: FastGPTFeConfigsType;
var systemEnv: SystemEnvType;
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
// System hook
const { data, refetch: refetchUnRead } = useQuery(['getUnreadCount'], getUnreadCount, {
enabled: !!userInfo && !!feConfigs.isPlus,
refetchInterval: 10000
refetchInterval: 30000
});
const unread = data?.unReadCount || 0;
const importantInforms = data?.importantInforms || [];
Expand Down
1 change: 1 addition & 0 deletions projects/app/src/global/common/api/systemRes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/i
import { SubPlanType } from '@fastgpt/global/support/wallet/sub/type';

export type InitDateResponse = {
bufferId?: string;
llmModels: LLMModelItemType[];
vectorModels: VectorModelItemType[];
audioSpeechModels: AudioSpeechModels[];
Expand Down
62 changes: 35 additions & 27 deletions projects/app/src/pages/api/common/system/getInitData.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import type { InitDateResponse } from '@/global/common/api/systemRes';
import type { NextApiResponse } from 'next';
import { connectToDatabase } from '@/service/mongo';
import { jsonRes } from '@fastgpt/service/common/response';
import { ApiRequestProps } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry';

async function handler(req: NextApiRequest, res: NextApiResponse) {
async function handler(req: ApiRequestProps<{}, { bufferId?: string }>, res: NextApiResponse) {
await connectToDatabase();

jsonRes<InitDateResponse>(res, {
data: {
feConfigs: global.feConfigs,
subPlans: global.subPlans,
llmModels: global.llmModels.map((model) => ({
...model,
customCQPrompt: '',
customExtractPrompt: '',
defaultSystemChatPrompt: ''
})),
vectorModels: global.vectorModels,
reRankModels:
global.reRankModels?.map((item) => ({
...item,
requestUrl: '',
requestAuth: ''
})) || [],
whisperModel: global.whisperModel,
audioSpeechModels: global.audioSpeechModels,
systemVersion: global.systemVersion || '0.0.0'
}
});
const { bufferId } = req.query;

// If bufferId is the same as the current bufferId, return directly
if (bufferId && global.systemInitBufferId && global.systemInitBufferId === bufferId) {
return {
bufferId: global.systemInitBufferId
};
}

return {
bufferId: global.systemInitBufferId,
feConfigs: global.feConfigs,
subPlans: global.subPlans,
llmModels: global.llmModels.map((model) => ({
...model,
customCQPrompt: '',
customExtractPrompt: '',
defaultSystemChatPrompt: ''
})),
vectorModels: global.vectorModels,
reRankModels:
global.reRankModels?.map((item) => ({
...item,
requestUrl: '',
requestAuth: ''
})) || [],
whisperModel: global.whisperModel,
audioSpeechModels: global.audioSpeechModels,
systemVersion: global.systemVersion || '0.0.0'
};
}

export default handler;
export default NextAPI(handler);
33 changes: 4 additions & 29 deletions projects/app/src/service/common/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export async function getInitConfig() {
getSystemVersion(),

// abandon
getSystemPlugin(),
getSystemPluginV1()
getSystemPlugin()
]);
}

Expand All @@ -79,7 +78,7 @@ const defaultFeConfigs: FastGPTFeConfigsType = {

export async function initSystemConfig() {
// load config
const [dbConfig, fileConfig] = await Promise.all([
const [{ config: dbConfig, configId }, fileConfig] = await Promise.all([
getFastGPTConfigFromDB(),
readConfigData('config.json')
]);
Expand All @@ -106,7 +105,9 @@ export async function initSystemConfig() {
};

// set config
global.systemInitBufferId = configId;
initFastGPTConfig(config);

console.log({
feConfigs: global.feConfigs,
systemEnv: global.systemEnv,
Expand Down Expand Up @@ -162,32 +163,6 @@ function getSystemPlugin() {

global.communityPlugins = fileTemplates;
}
function getSystemPluginV1() {
if (global.communityPluginsV1 && global.communityPluginsV1.length > 0) return;

const basePath =
process.env.NODE_ENV === 'development'
? 'data/pluginTemplates/v1'
: '/app/data/pluginTemplates/v1';
// read data/pluginTemplates directory, get all json file
const files = readdirSync(basePath);
// filter json file
const filterFiles = files.filter((item) => item.endsWith('.json'));

// read json file
const fileTemplates: (PluginTemplateType & { weight: number })[] = filterFiles.map((filename) => {
const content = readFileSync(`${basePath}/${filename}`, 'utf-8');
return {
...JSON.parse(content),
id: `${PluginSourceEnum.community}-${filename.replace('.json', '')}`,
source: PluginSourceEnum.community
};
});

fileTemplates.sort((a, b) => b.weight - a.weight);

global.communityPluginsV1 = fileTemplates;
}

export async function initSystemPlugins() {
try {
Expand Down
5 changes: 4 additions & 1 deletion projects/app/src/web/common/system/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { InitDateResponse } from '@/global/common/api/systemRes';
import { GET } from '@/web/common/api/request';

export const getSystemInitData = () => GET<InitDateResponse>('/common/system/getInitData');
export const getSystemInitData = (bufferId?: string) =>
GET<InitDateResponse>('/common/system/getInitData', {
bufferId
});
2 changes: 1 addition & 1 deletion projects/app/src/web/common/system/staticData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const clientInitData = async (
feConfigs: FastGPTFeConfigsType;
}> => {
try {
const res = await getSystemInitData();
const res = await getSystemInitData(useSystemStore.getState().initDataBufferId);
useSystemStore.getState().initStaticData(res);

return {
Expand Down
24 changes: 19 additions & 5 deletions projects/app/src/web/common/system/useSystemStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type State = {
isNotSufficientModal: boolean;
setIsNotSufficientModal: (val: boolean) => void;

initDataBufferId?: string;
feConfigs: FastGPTFeConfigsType;
subPlans?: SubPlanType;
systemVersion: string;
Expand Down Expand Up @@ -111,6 +112,7 @@ export const useSystemStore = create<State>()(
});
},

initDataBufferId: undefined,
feConfigs: {},
subPlans: undefined,
systemVersion: '0.0.0',
Expand All @@ -122,23 +124,35 @@ export const useSystemStore = create<State>()(
whisperModel: defaultWhisperModel,
initStaticData(res) {
set((state) => {
state.feConfigs = res.feConfigs || {};
state.subPlans = res.subPlans;
state.systemVersion = res.systemVersion;
state.initDataBufferId = res.bufferId;

state.feConfigs = res.feConfigs ?? state.feConfigs;
state.subPlans = res.subPlans ?? state.subPlans;
state.systemVersion = res.systemVersion ?? state.systemVersion;

state.llmModelList = res.llmModels ?? state.llmModelList;
state.datasetModelList = state.llmModelList.filter((item) => item.datasetProcess);
state.vectorModelList = res.vectorModels ?? state.vectorModelList;
state.audioSpeechModelList = res.audioSpeechModels ?? state.audioSpeechModelList;
state.reRankModelList = res.reRankModels ?? state.reRankModelList;
state.whisperModel = res.whisperModel;
state.whisperModel = res.whisperModel ?? state.whisperModel;
});
}
})),
{
name: 'globalStore',
partialize: (state) => ({
loginStore: state.loginStore
loginStore: state.loginStore,
initDataBufferId: state.initDataBufferId,
feConfigs: state.feConfigs,
subPlans: state.subPlans,
systemVersion: state.systemVersion,
llmModelList: state.llmModelList,
datasetModelList: state.datasetModelList,
vectorModelList: state.vectorModelList,
audioSpeechModelList: state.audioSpeechModelList,
reRankModelList: state.reRankModelList,
whisperModel: state.whisperModel
})
}
)
Expand Down
8 changes: 6 additions & 2 deletions projects/app/src/web/context/useInitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSystemStore } from '@/web/common/system/useSystemStore';
import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/index.d';
import { useMemoizedFn, useMount } from 'ahooks';
import { TrackEventName } from '../common/system/constants';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';

export const useInitApp = () => {
const router = useRouter();
Expand Down Expand Up @@ -41,8 +42,6 @@ export const useInitApp = () => {
});

useMount(() => {
initFetch();

const errorTrack = (event: ErrorEvent) => {
window.umami?.track(TrackEventName.windowError, {
device: {
Expand All @@ -62,6 +61,11 @@ export const useInitApp = () => {
};
});

useRequest2(initFetch, {
manual: false,
pollingInterval: 300000
});

useEffect(() => {
hiId && localStorage.setItem('inviterId', hiId);
bd_vid && sessionStorage.setItem('bd_vid', bd_vid);
Expand Down

0 comments on commit 2c18f1d

Please sign in to comment.