fix: config

This commit is contained in:
archer
2023-08-05 11:51:40 +08:00
parent 761ae74b0a
commit 37a6293f5e
11 changed files with 39 additions and 67 deletions

View File

@@ -95,27 +95,7 @@ const appSchema = new mongoose.Schema({
updateTime: Date
});
const SystemSchema = new mongoose.Schema({
vectorMaxProcess: {
type: Number,
default: 10
},
qaMaxProcess: {
type: Number,
default: 10
},
pgIvfflatProbe: {
type: Number,
default: 10
},
sensitiveCheck: {
type: Boolean,
default: false
}
});
export const App = mongoose.models['app'] || mongoose.model('app', appSchema);
export const Kb = mongoose.models['kb'] || mongoose.model('kb', kbSchema);
export const User = mongoose.models['user'] || mongoose.model('user', UserSchema);
export const Pay = mongoose.models['pay'] || mongoose.model('pay', paySchema);
export const System = mongoose.models['system'] || mongoose.model('system', SystemSchema);

2
client/.gitignore vendored
View File

@@ -29,4 +29,4 @@ platform.json
testApi/
local/
.husky/
data/config.json.local
data/*.local

View File

@@ -5,15 +5,14 @@
"show_appStore": false,
"show_userDetail": false,
"show_git": true,
"beianText": "",
"systemTitle": "FastAI",
"authorText": "Made by FastAI Team."
},
"SystemParams": {
"beianText": "",
"vectorMaxProcess": 15,
"qaMaxProcess": 15,
"pgIvfflatProbe": 20,
"sensitiveCheck": false
"pgIvfflatProbe": 20
},
"ChatModels": [
{
@@ -63,5 +62,6 @@
"name": "Embedding-2",
"price": 0.2
}
]
],
"plugins": {}
}

View File

@@ -4,7 +4,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
let timer: any;
import { useToast } from './useToast';
import { getClientToken } from '@/utils/plugin/google';
import { googleClientVerKey } from '@/store/static';
import { feConfigs } from '@/store/static';
export const useSendCode = () => {
const { toast } = useToast();
@@ -27,7 +27,7 @@ export const useSendCode = () => {
await sendAuthCode({
username,
type,
googleToken: await getClientToken(googleClientVerKey)
googleToken: await getClientToken(feConfigs.googleClientVerKey)
});
setCodeCountDown(60);
timer = setInterval(() => {

View File

@@ -37,15 +37,15 @@ function App({ Component, pageProps }: AppProps) {
const { i18n } = useTranslation();
const [googleClientVerKey, setGoogleVerKey] = useState<string>();
const [baiduTongji, setBaiduTongji] = useState<string>();
const [baiduTongjiUrl, setBaiduTongjiUrl] = useState<string>();
useEffect(() => {
(async () => {
const {
systemEnv: { googleClientVerKey, baiduTongji }
feConfigs: { googleClientVerKey, baiduTongjiUrl }
} = await clientInitData();
setGoogleVerKey(googleClientVerKey);
setBaiduTongji(baiduTongji);
setBaiduTongjiUrl(baiduTongjiUrl);
})();
}, []);
@@ -69,7 +69,7 @@ function App({ Component, pageProps }: AppProps) {
<Script src="/js/qrcode.min.js" strategy="lazyOnload"></Script>
<Script src="/js/pdf.js" strategy="lazyOnload"></Script>
<Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script>
{baiduTongji && <Script src={baiduTongji} strategy="lazyOnload"></Script>}
{baiduTongjiUrl && <Script src={baiduTongjiUrl} strategy="lazyOnload"></Script>}
{googleClientVerKey && (
<>
<Script

View File

@@ -28,10 +28,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
export async function sensitiveCheck({ input }: Props) {
if (!global.systemEnv.sensitiveCheck) {
return Promise.resolve('');
}
const response = await axios({
...axiosConfig(),
method: 'POST',

View File

@@ -1,4 +1,4 @@
import type { FeConfigsType, SystemEnvType } from '@/types';
import type { FeConfigsType } from '@/types';
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { readFileSync } from 'fs';
@@ -12,7 +12,6 @@ export type InitDateResponse = {
chatModels: ChatModelItemType[];
qaModels: QAModelItemType[];
vectorModels: VectorModelItemType[];
systemEnv: SystemEnvType;
feConfigs: FeConfigsType;
};
@@ -22,7 +21,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
jsonRes<InitDateResponse>(res, {
data: {
systemEnv: global.systemEnv,
feConfigs: global.feConfigs,
chatModels: global.chatModels,
qaModels: global.qaModels,
@@ -34,8 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const defaultSystemEnv = {
vectorMaxProcess: 15,
qaMaxProcess: 15,
pgIvfflatProbe: 20,
sensitiveCheck: false
pgIvfflatProbe: 20
};
const defaultFeConfigs = {
show_emptyChat: true,
@@ -102,7 +99,7 @@ export async function getInitConfig() {
global.vectorModels = res.VectorModels || defaultVectorModels;
} catch (error) {
setDefaultData();
console.log('get init config error, set default');
console.log('get init config error, set default', error);
}
}

View File

@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
import { Card, Box, Link, Flex, Image, Button } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { useGlobalStore } from '@/store/global';
import { beianText } from '@/store/static';
import { feConfigs } from '@/store/static';
import { serviceSideProps } from '@/utils/i18n';
import { useTranslation } from 'next-i18next';
@@ -215,19 +214,17 @@ const Home = () => {
</Flex>
</Flex>
{feConfigs?.authorText && (
<Box w={'100%'} mt={'100vh'} px={[5, 10]} pb={[5, 10]}>
<Card p={5} mt={4} textAlign={'center'}>
{beianText && (
<Link href="https://beian.miit.gov.cn/" target="_blank">
{beianText}
</Link>
)}
<Box w={'100%'} mt={'100vh'} px={[5, 10]} pb={[5, 10]}>
<Card p={5} mt={4} textAlign={'center'}>
{feConfigs?.beianText && (
<Link href="https://beian.miit.gov.cn/" target="_blank">
{feConfigs.beianText}
</Link>
)}
<Box>{feConfigs?.authorText}</Box>
</Card>
</Box>
)}
{feConfigs?.authorText && <Box>{feConfigs?.authorText}</Box>}
</Card>
</Box>
</Flex>
);
};

View File

@@ -22,8 +22,7 @@ export async function connectToDatabase(): Promise<void> {
global.systemEnv = {
vectorMaxProcess: 10,
qaMaxProcess: 10,
pgIvfflatProbe: 10,
sensitiveCheck: false
pgIvfflatProbe: 10
};
global.sendInformQueue = [];
global.sendInformQueueLen = 0;

View File

@@ -8,9 +8,6 @@ import { getInitData } from '@/api/system';
import { delay } from '@/utils/tools';
import { FeConfigsType } from '@/types';
export let beianText: string | undefined;
export let googleClientVerKey: string | undefined;
export let baiduTongji: string | undefined;
export let chatModelList: ChatModelItemType[] = [];
export let qaModelList: QAModelItemType[] = [];
export let vectorModelList: VectorModelItemType[] = [];
@@ -26,9 +23,6 @@ export const clientInitData = async (): Promise<InitDateResponse> => {
qaModelList = res.qaModels;
vectorModelList = res.vectorModels;
feConfigs = res.feConfigs;
beianText = res.systemEnv?.beianText;
googleClientVerKey = res.systemEnv?.googleClientVerKey;
baiduTongji = res.systemEnv?.baiduTongji;
return res;
} catch (error) {

View File

@@ -21,16 +21,23 @@ export type FeConfigsType = {
show_git?: boolean;
systemTitle?: string;
authorText?: string;
};
export type SystemEnvType = {
beianText?: string;
googleClientVerKey?: string;
baiduTongjiUrl?: string;
};
export type SystemEnvType = {
googleServiceVerKey?: string;
baiduTongji?: string;
vectorMaxProcess: number;
qaMaxProcess: number;
pgIvfflatProbe: number;
sensitiveCheck: boolean;
};
type PluginItemType = {
url: string;
auth: string;
};
export type PluginType = {
authCode?: PluginItemType;
moderationsCheck?: PluginItemType;
};
declare global {
@@ -42,11 +49,13 @@ declare global {
var OpenAiEncMap: Tiktoken;
var sendInformQueue: (() => Promise<void>)[];
var sendInformQueueLen: number;
var feConfigs: FeConfigsType;
var systemEnv: SystemEnvType;
var;
var chatModels: ChatModelItemType[];
var qaModels: QAModelItemType[];
var vectorModels: VectorModelItemType[];
var feConfigs: FeConfigsType;
interface Window {
['pdfjs-dist/build/pdf']: any;