mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 02:12:38 +00:00

* 4.7-alpha3 (#62) * doc * Optimize possible null Pointers and parts of Ux * fix: mulity index training error * feat: doc and rename question guide * fix ios speech input (#59) * fix: prompt editor variables nowrap (#61) * change openapi import in http module with curl import (#60) * chore(ui): dataset import modal ui (#58) * chore(ui): dataset import modal ui * use component * fix height * 4.7 (#63) * fix: claude3 image type verification failed (#1038) (#1040) * perf: curl import modal * doc img * perf: adapt cohere rerank * perf: code * perf: input style * doc --------- Co-authored-by: xiaotian <dimsky@163.com> * fix: ts * docker deploy * perf: prompt call * doc * ts * finish ui * perf: outlink detail ux * perf: user schema * fix: plugin update * feat: get current time plugin * fix: ts * perf: fetch anamation * perf: mark ux * doc * perf: select app ux * fix: split text custom string conflict * peref: inform readed * doc * memo flow component * perf: version * faq * feat: flow max runtimes * feat: similarity tip * feat: auto detect file encoding * Supports asymmetric vector model * fix: ts * perf: max w * move code * perf: hide whisper * fix: ts * feat: system msg modal * perf: catch error * perf: inform tip * fix: inform --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com> Co-authored-by: xiaotian <dimsky@163.com>
166 lines
5.2 KiB
TypeScript
166 lines
5.2 KiB
TypeScript
import type { FastGPTFeConfigsType } from '@fastgpt/global/common/system/types/index.d';
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { jsonRes } from '@fastgpt/service/common/response';
|
|
import { readFileSync, readdirSync } from 'fs';
|
|
import type { InitDateResponse } from '@/global/common/api/systemRes';
|
|
import type { FastGPTConfigFileType } from '@fastgpt/global/common/system/types/index.d';
|
|
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
|
|
import { getFastGPTConfigFromDB } from '@fastgpt/service/common/system/config/controller';
|
|
import { connectToDatabase } from '@/service/mongo';
|
|
import { PluginTemplateType } from '@fastgpt/global/core/plugin/type';
|
|
import { readConfigData } from '@/service/common/system';
|
|
import { exit } from 'process';
|
|
import { FastGPTProUrl } from '@fastgpt/service/common/system/constants';
|
|
import { initFastGPTConfig } from '@fastgpt/service/common/system/tools';
|
|
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
await getInitConfig();
|
|
|
|
jsonRes<InitDateResponse>(res, {
|
|
data: {
|
|
feConfigs: global.feConfigs,
|
|
subPlans: global.subPlans,
|
|
llmModels: global.llmModels,
|
|
vectorModels: global.vectorModels,
|
|
reRankModels:
|
|
global.reRankModels?.map((item) => ({
|
|
...item,
|
|
requestUrl: '',
|
|
requestAuth: ''
|
|
})) || [],
|
|
whisperModel: global.whisperModel,
|
|
audioSpeechModels: global.audioSpeechModels,
|
|
systemVersion: global.systemVersion || '0.0.0'
|
|
}
|
|
});
|
|
}
|
|
|
|
const defaultFeConfigs: FastGPTFeConfigsType = {
|
|
show_emptyChat: true,
|
|
show_git: true,
|
|
docUrl: 'https://doc.fastgpt.in',
|
|
openAPIDocUrl: 'https://doc.fastgpt.in/docs/development/openapi',
|
|
systemTitle: 'FastGPT',
|
|
concatMd:
|
|
'项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n交流群: ',
|
|
limit: {
|
|
exportDatasetLimitMinutes: 0,
|
|
websiteSyncLimitMinuted: 0
|
|
},
|
|
scripts: [],
|
|
favicon: '/favicon.ico',
|
|
uploadFileMaxSize: 500
|
|
};
|
|
|
|
export async function getInitConfig() {
|
|
if (global.systemInitd) return;
|
|
global.systemInitd = true;
|
|
|
|
try {
|
|
await connectToDatabase();
|
|
|
|
await Promise.all([
|
|
initSystemConfig(),
|
|
// getSimpleModeTemplates(),
|
|
getSystemVersion(),
|
|
getSystemPlugin()
|
|
]);
|
|
|
|
console.log({
|
|
communityPlugins: global.communityPlugins
|
|
});
|
|
} catch (error) {
|
|
console.error('Load init config error', error);
|
|
global.systemInitd = false;
|
|
|
|
if (!global.feConfigs) {
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function initSystemConfig() {
|
|
// load config
|
|
const [dbConfig, fileConfig] = await Promise.all([
|
|
getFastGPTConfigFromDB(),
|
|
readConfigData('config.json')
|
|
]);
|
|
const fileRes = JSON.parse(fileConfig) as FastGPTConfigFileType;
|
|
|
|
// get config from database
|
|
const config: FastGPTConfigFileType = {
|
|
feConfigs: {
|
|
...defaultFeConfigs,
|
|
...(dbConfig.feConfigs || {}),
|
|
isPlus: !!FastGPTProUrl
|
|
},
|
|
systemEnv: {
|
|
...fileRes.systemEnv,
|
|
...(dbConfig.systemEnv || {})
|
|
},
|
|
subPlans: dbConfig.subPlans || fileRes.subPlans,
|
|
llmModels: dbConfig.llmModels || fileRes.llmModels || [],
|
|
vectorModels: dbConfig.vectorModels || fileRes.vectorModels || [],
|
|
reRankModels: dbConfig.reRankModels || fileRes.reRankModels || [],
|
|
audioSpeechModels: dbConfig.audioSpeechModels || fileRes.audioSpeechModels || [],
|
|
whisperModel: dbConfig.whisperModel || fileRes.whisperModel
|
|
};
|
|
|
|
// set config
|
|
initFastGPTConfig(config);
|
|
|
|
console.log({
|
|
feConfigs: global.feConfigs,
|
|
systemEnv: global.systemEnv,
|
|
subPlans: global.subPlans,
|
|
llmModels: global.llmModels,
|
|
vectorModels: global.vectorModels,
|
|
reRankModels: global.reRankModels,
|
|
audioSpeechModels: global.audioSpeechModels,
|
|
whisperModel: global.whisperModel
|
|
});
|
|
}
|
|
|
|
export function getSystemVersion() {
|
|
if (global.systemVersion) return;
|
|
try {
|
|
if (process.env.NODE_ENV === 'development') {
|
|
global.systemVersion = process.env.npm_package_version || '0.0.0';
|
|
} else {
|
|
const packageJson = JSON.parse(readFileSync('/app/package.json', 'utf-8'));
|
|
|
|
global.systemVersion = packageJson?.version;
|
|
}
|
|
console.log(`System Version: ${global.systemVersion}`);
|
|
} catch (error) {
|
|
console.log(error);
|
|
|
|
global.systemVersion = '0.0.0';
|
|
}
|
|
}
|
|
|
|
function getSystemPlugin() {
|
|
if (global.communityPlugins && global.communityPlugins.length > 0) return;
|
|
|
|
const basePath =
|
|
process.env.NODE_ENV === 'development' ? 'data/pluginTemplates' : '/app/data/pluginTemplates';
|
|
// 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.communityPlugins = fileTemplates;
|
|
}
|