diff --git a/client/data/ChatModels.json b/client/data/ChatModels.json deleted file mode 100644 index 324a3f9da..000000000 --- a/client/data/ChatModels.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "FastAI-4k": { - "model": "gpt-3.5-turbo", - "name": "FastAI-4k", - "contextMaxToken": 4000, - "systemMaxToken": 2400, - "maxTemperature": 1.2, - "price": 1.5 - }, - "FastAI-16k": { - "model": "gpt-3.5-turbo-16k", - "name": "FastAI-16k", - "contextMaxToken": 16000, - "systemMaxToken": 8000, - "maxTemperature": 1.2, - "price": 3 - }, - "FastAI-Plus": { - "model": "gpt-4", - "name": "FastAI-Plus", - "contextMaxToken": 8000, - "systemMaxToken": 4000, - "maxTemperature": 1.2, - "price": 45 - } -} diff --git a/client/data/FeConfig.json b/client/data/FeConfig.json deleted file mode 100644 index 223ea265f..000000000 --- a/client/data/FeConfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "show_emptyChat": true, - "show_register": true, - "show_appStore": true, - "show_userDetail": true, - "show_git": true, - "systemTitle": "FastAI", - "authorText": "Made by FastAI Team." -} diff --git a/client/data/QAModels.json b/client/data/QAModels.json deleted file mode 100644 index 525035ca1..000000000 --- a/client/data/QAModels.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "FastAI-16k": { - "model": "gpt-3.5-turbo-16k", - "name": "FastAI-16k", - "maxToken": 16000, - "price": 3 - } -} diff --git a/client/data/SystemParams.json b/client/data/SystemParams.json deleted file mode 100644 index e7bcacd4d..000000000 --- a/client/data/SystemParams.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "vectorMaxProcess": 15, - "qaMaxProcess": 15, - "pgIvfflatProbe": 20, - "sensitiveCheck": false -} diff --git a/client/data/VectorModels.json b/client/data/VectorModels.json deleted file mode 100644 index 3e3aee8b0..000000000 --- a/client/data/VectorModels.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "text-embedding-ada-002": { - "model": "text-embedding-ada-002", - "name": "Embedding-2", - "price": 0.2 - } -} diff --git a/client/data/config.json b/client/data/config.json new file mode 100644 index 000000000..55cbc458e --- /dev/null +++ b/client/data/config.json @@ -0,0 +1,61 @@ +{ + "FeConfig": { + "show_emptyChat": true, + "show_register": true, + "show_appStore": true, + "show_userDetail": true, + "show_git": true, + "systemTitle": "FastAI", + "authorText": "Made by FastAI Team." + }, + "SystemParams": { + "beianText": "", + "googleVerKey": "", + "baiduTongji": "", + "vectorMaxProcess": 15, + "qaMaxProcess": 15, + "pgIvfflatProbe": 20, + "sensitiveCheck": false + }, + "ChatModels": [ + { + "model": "gpt-3.5-turbo", + "name": "FastAI-4k", + "contextMaxToken": 4000, + "systemMaxToken": 2400, + "maxTemperature": 1.2, + "price": 1.5 + }, + { + "model": "gpt-3.5-turbo-16k", + "name": "FastAI-16k", + "contextMaxToken": 16000, + "systemMaxToken": 8000, + "maxTemperature": 1.2, + "price": 3 + }, + { + "model": "gpt-4", + "name": "FastAI-Plus", + "contextMaxToken": 8000, + "systemMaxToken": 4000, + "maxTemperature": 1.2, + "price": 45 + } + ], + "QAModels": [ + { + "model": "gpt-3.5-turbo-16k", + "name": "FastAI-16k", + "maxToken": 16000, + "price": 3 + } + ], + "VectorModels": [ + { + "model": "text-embedding-ada-002", + "name": "Embedding-2", + "price": 0.2 + } + ] +} diff --git a/client/src/components/Layout/navbar.tsx b/client/src/components/Layout/navbar.tsx index 0a56cfd54..388ce7b68 100644 --- a/client/src/components/Layout/navbar.tsx +++ b/client/src/components/Layout/navbar.tsx @@ -19,50 +19,47 @@ const Navbar = ({ unread }: { unread: number }) => { const router = useRouter(); const { userInfo } = useUserStore(); const { lastChatAppId, lastChatId } = useChatStore(); - const navbarList = useMemo( - () => [ - { - label: '聊天', - icon: 'chatLight', - activeIcon: 'chatFill', - link: `/chat?appId=${lastChatAppId}&chatId=${lastChatId}`, - activeLink: ['/chat'] - }, - { - label: '应用', - icon: 'appLight', - activeIcon: 'appFill', - link: `/app/list`, - activeLink: ['/app/list', '/app/detail'] - }, - { - label: '知识库', - icon: 'dbLight', - activeIcon: 'dbFill', - link: `/kb/list`, - activeLink: ['/kb/list', '/kb/detail'] - }, - ...(feConfigs?.show_appStore - ? [ - { - label: '市场', - icon: 'appStoreLight', - activeIcon: 'appStoreFill', - link: '/appStore', - activeLink: ['/appStore'] - } - ] - : []), - { - label: '账号', - icon: 'meLight', - activeIcon: 'meFill', - link: '/number', - activeLink: ['/number'] - } - ], - [lastChatId, lastChatAppId] - ); + const navbarList = [ + { + label: '聊天', + icon: 'chatLight', + activeIcon: 'chatFill', + link: `/chat?appId=${lastChatAppId}&chatId=${lastChatId}`, + activeLink: ['/chat'] + }, + { + label: '应用', + icon: 'appLight', + activeIcon: 'appFill', + link: `/app/list`, + activeLink: ['/app/list', '/app/detail'] + }, + { + label: '知识库', + icon: 'dbLight', + activeIcon: 'dbFill', + link: `/kb/list`, + activeLink: ['/kb/list', '/kb/detail'] + }, + ...(feConfigs?.show_appStore + ? [ + { + label: '市场', + icon: 'appStoreLight', + activeIcon: 'appStoreFill', + link: '/appStore', + activeLink: ['/appStore'] + } + ] + : []), + { + label: '账号', + icon: 'meLight', + activeIcon: 'meFill', + link: '/number', + activeLink: ['/number'] + } + ]; const itemStyles: any = { my: 3, diff --git a/client/src/pages/_app.tsx b/client/src/pages/_app.tsx index 025646cb0..c8dffa156 100644 --- a/client/src/pages/_app.tsx +++ b/client/src/pages/_app.tsx @@ -41,7 +41,9 @@ function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; respon useEffect(() => { (async () => { - const { googleVerKey, baiduTongji } = await clientInitData(); + const { + systemEnv: { googleVerKey, baiduTongji } + } = await clientInitData(); setGoogleVerKey(googleVerKey); setBaiduTongji(baiduTongji); })(); diff --git a/client/src/pages/api/system/getInitData.ts b/client/src/pages/api/system/getInitData.ts index e8f3a05f9..a2fbb4b63 100644 --- a/client/src/pages/api/system/getInitData.ts +++ b/client/src/pages/api/system/getInitData.ts @@ -1,37 +1,44 @@ -// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import type { FeConfigsType, SystemEnvType } from '@/types'; import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; +import { readFileSync } from 'fs'; import { type QAModelItemType, type ChatModelItemType, type VectorModelItemType } from '@/types/model'; -import type { FeConfigsType } from '@/types'; export type InitDateResponse = { - beianText: string; - googleVerKey: string; - baiduTongji: string; chatModels: ChatModelItemType[]; qaModels: QAModelItemType[]; vectorModels: VectorModelItemType[]; + systemEnv: SystemEnvType; feConfigs: FeConfigsType; }; export default async function handler(req: NextApiRequest, res: NextApiResponse) { - const envs = { - beianText: process.env.SAFE_BEIAN_TEXT || '', - googleVerKey: process.env.CLIENT_GOOGLE_VER_TOKEN || '', - baiduTongji: process.env.BAIDU_TONGJI || '' - }; - jsonRes(res, { data: { - ...envs, + systemEnv: global.systemEnv, + feConfigs: global.feConfigs, chatModels: global.chatModels, qaModels: global.qaModels, - vectorModels: global.vectorModels, - feConfigs: global.feConfigs + vectorModels: global.vectorModels } }); } + +export async function getInitConfig() { + try { + const res = JSON.parse(readFileSync('data/config.json', 'utf-8')); + console.log(res); + + global.systemEnv = res.SystemParams; + global.feConfigs = res.FeConfig; + global.chatModels = res.ChatModels; + global.qaModels = res.QAModels; + global.vectorModels = res.VectorModels; + } catch (error) { + console.log('get init config error'); + } +} diff --git a/client/src/pages/api/system/updateEnv.ts b/client/src/pages/api/system/updateEnv.ts deleted file mode 100644 index fa11e2c42..000000000 --- a/client/src/pages/api/system/updateEnv.ts +++ /dev/null @@ -1,123 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from 'next'; -import { jsonRes } from '@/service/response'; -import { authUser } from '@/service/utils/auth'; -import { readFileSync } from 'fs'; -import { - type QAModelItemType, - type ChatModelItemType, - type VectorModelItemType -} from '@/types/model'; - -export default async function handler(req: NextApiRequest, res: NextApiResponse) { - await authUser({ req, authRoot: true }); - updateSystemEnv(); - jsonRes(res); -} - -export async function updateSystemEnv() { - try { - const res = JSON.parse(readFileSync('data/SystemParams.json', 'utf-8')); - - global.systemEnv = { - ...global.systemEnv, - ...res - }; - console.log(global.systemEnv); - } catch (error) { - console.log('update system env error'); - } -} - -const defaultmodels = { - 'FastAI-4k': { - model: 'gpt-3.5-turbo', - name: 'FastAI-4k', - contextMaxToken: 4000, - systemMaxToken: 2400, - maxTemperature: 1.2, - price: 1.5 - }, - 'FastAI-16k': { - model: 'gpt-3.5-turbo', - name: 'FastAI-16k', - contextMaxToken: 16000, - systemMaxToken: 8000, - maxTemperature: 1.2, - price: 3 - }, - 'FastAI-Plus': { - model: 'gpt-4', - name: 'FastAI-Plus', - contextMaxToken: 8000, - systemMaxToken: 4000, - maxTemperature: 1.2, - price: 45 - } -}; -const defaultQaModels = { - 'FastAI-16k': { - model: 'gpt-3.5-turbo', - name: 'FastAI-16k', - maxToken: 16000, - price: 3 - } -}; -const defaultVectorModels = { - 'text-embedding-ada-002': { - model: 'text-embedding-ada-002', - name: 'Embedding-2', - price: 0.2 - } -}; -export function initSystemModels() { - const { chatModels, qaModels, vectorModels } = (() => { - try { - const chatModels = Object.values(JSON.parse(readFileSync('data/ChatModels.json', 'utf-8'))); - const qaModels = Object.values(JSON.parse(readFileSync('data/QAModels.json', 'utf-8'))); - const vectorModels = Object.values( - JSON.parse(readFileSync('data/VectorModels.json', 'utf-8')) - ); - - return { - chatModels, - qaModels, - vectorModels - }; - } catch (error) { - console.log(error); - - return { - chatModels: Object.values(defaultmodels), - qaModels: Object.values(defaultQaModels), - vectorModels: Object.values(defaultVectorModels) - }; - } - })() as { - chatModels: ChatModelItemType[]; - qaModels: QAModelItemType[]; - vectorModels: VectorModelItemType[]; - }; - global.chatModels = chatModels; - global.qaModels = qaModels; - global.vectorModels = vectorModels; - console.log({ - chatModels, - qaModels, - vectorModels - }); - - return { - chatModels, - qaModels, - vectorModels - }; -} - -export function initFeConfig() { - const feConfig = JSON.parse(readFileSync('data/FeConfig.json', 'utf-8')); - - global.feConfigs = feConfig; - console.log(feConfig); - - return feConfig; -} diff --git a/client/src/pages/number/index.tsx b/client/src/pages/number/index.tsx index 529fe781e..372b71510 100644 --- a/client/src/pages/number/index.tsx +++ b/client/src/pages/number/index.tsx @@ -147,7 +147,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => { ); return ( - <> + @@ -257,7 +257,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => { {isOpenPayModal && } {isOpenWxConcat && } - + ); }; diff --git a/client/src/service/mongo.ts b/client/src/service/mongo.ts index 1e06c3a9d..06e4a1498 100644 --- a/client/src/service/mongo.ts +++ b/client/src/service/mongo.ts @@ -1,7 +1,7 @@ import mongoose from 'mongoose'; import tunnel from 'tunnel'; import { startQueue } from './utils/tools'; -import { updateSystemEnv, initSystemModels, initFeConfig } from '@/pages/api/system/updateEnv'; +import { getInitConfig } from '@/pages/api/system/getInitData'; /** * 连接 MongoDB 数据库 @@ -23,7 +23,6 @@ export async function connectToDatabase(): Promise { }; global.sendInformQueue = []; global.sendInformQueueLen = 0; - global.feConfigs = {}; // proxy obj if (process.env.AXIOS_PROXY_HOST && process.env.AXIOS_PROXY_PORT) { global.httpsAgent = tunnel.httpsOverHttp({ @@ -35,9 +34,7 @@ export async function connectToDatabase(): Promise { } // init function - initSystemModels(); - initFeConfig(); - updateSystemEnv(); + getInitConfig(); try { mongoose.set('strictQuery', true); diff --git a/client/src/store/static.ts b/client/src/store/static.ts index c98cab820..5d7de1a3b 100644 --- a/client/src/store/static.ts +++ b/client/src/store/static.ts @@ -8,9 +8,9 @@ import { getInitData } from '@/api/system'; import { delay } from '@/utils/tools'; import { FeConfigsType } from '@/types'; -export let beianText = ''; -export let googleVerKey = ''; -export let baiduTongji = ''; +export let beianText: string | undefined; +export let googleVerKey: string | undefined; +export let baiduTongji: string | undefined; export let chatModelList: ChatModelItemType[] = []; export let qaModelList: QAModelItemType[] = []; export let vectorModelList: VectorModelItemType[] = []; @@ -26,9 +26,10 @@ export const clientInitData = async (): Promise => { qaModelList = res.qaModels; vectorModelList = res.vectorModels; feConfigs = res.feConfigs; - beianText = res.beianText; - googleVerKey = res.googleVerKey; - baiduTongji = res.baiduTongji; + beianText = res.systemEnv.beianText; + googleVerKey = res.systemEnv.googleVerKey; + baiduTongji = res.systemEnv.baiduTongji; + console.log(res); return res; } catch (error) { diff --git a/client/src/types/index.d.ts b/client/src/types/index.d.ts index 9b84f06ef..78c8a5ede 100644 --- a/client/src/types/index.d.ts +++ b/client/src/types/index.d.ts @@ -22,6 +22,15 @@ export type FeConfigsType = { systemTitle?: string; authorText?: string; }; +export type SystemEnvType = { + beianText?: string; + googleVerKey?: string; + baiduTongji?: string; + vectorMaxProcess: number; + qaMaxProcess: number; + pgIvfflatProbe: number; + sensitiveCheck: boolean; +}; declare global { var mongodb: Mongoose | string | null; @@ -32,12 +41,7 @@ declare global { var OpenAiEncMap: Tiktoken; var sendInformQueue: (() => Promise)[]; var sendInformQueueLen: number; - var systemEnv: { - vectorMaxProcess: number; - qaMaxProcess: number; - pgIvfflatProbe: number; - sensitiveCheck: boolean; - }; + var systemEnv: SystemEnvType; var chatModels: ChatModelItemType[]; var qaModels: QAModelItemType[]; var vectorModels: VectorModelItemType[];