mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-20 10:45:52 +00:00
perf: chat source
This commit is contained in:
@@ -3,6 +3,7 @@ import { jsonRes } from '@/service/response';
|
|||||||
import { connectToDatabase, Chat } from '@/service/mongo';
|
import { connectToDatabase, Chat } from '@/service/mongo';
|
||||||
import { authUser } from '@/service/utils/auth';
|
import { authUser } from '@/service/utils/auth';
|
||||||
import type { ChatHistoryItemType } from '@/types/chat';
|
import type { ChatHistoryItemType } from '@/types/chat';
|
||||||
|
import { ChatSourceEnum } from '@/constants/chat';
|
||||||
|
|
||||||
/* 获取历史记录 */
|
/* 获取历史记录 */
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
@@ -15,6 +16,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const data = await Chat.find(
|
const data = await Chat.find(
|
||||||
{
|
{
|
||||||
userId,
|
userId,
|
||||||
|
source: ChatSourceEnum.online,
|
||||||
...(appId && { appId })
|
...(appId && { appId })
|
||||||
},
|
},
|
||||||
'chatId title top customTitle appId updateTime'
|
'chatId title top customTitle appId updateTime'
|
||||||
|
@@ -31,16 +31,73 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultSystemEnv = {
|
||||||
|
vectorMaxProcess: 15,
|
||||||
|
qaMaxProcess: 15,
|
||||||
|
pgIvfflatProbe: 20,
|
||||||
|
sensitiveCheck: false
|
||||||
|
};
|
||||||
|
const defaultFeConfigs = {
|
||||||
|
show_emptyChat: true,
|
||||||
|
show_register: true,
|
||||||
|
show_appStore: true,
|
||||||
|
show_userDetail: true,
|
||||||
|
show_git: true,
|
||||||
|
systemTitle: 'FastAI',
|
||||||
|
authorText: 'Made by FastAI Team.'
|
||||||
|
};
|
||||||
|
const defaultChatModels = [
|
||||||
|
{
|
||||||
|
model: 'gpt-3.5-turbo',
|
||||||
|
name: 'FastAI-4k',
|
||||||
|
contextMaxToken: 4000,
|
||||||
|
quoteMaxToken: 2400,
|
||||||
|
maxTemperature: 1.2,
|
||||||
|
price: 1.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: 'gpt-3.5-turbo-16k',
|
||||||
|
name: 'FastAI-16k',
|
||||||
|
contextMaxToken: 16000,
|
||||||
|
quoteMaxToken: 8000,
|
||||||
|
maxTemperature: 1.2,
|
||||||
|
price: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: 'gpt-4',
|
||||||
|
name: 'FastAI-Plus',
|
||||||
|
contextMaxToken: 8000,
|
||||||
|
quoteMaxToken: 4000,
|
||||||
|
maxTemperature: 1.2,
|
||||||
|
price: 45
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const defaultQAModels = [
|
||||||
|
{
|
||||||
|
model: 'gpt-3.5-turbo-16k',
|
||||||
|
name: 'FastAI-16k',
|
||||||
|
maxToken: 16000,
|
||||||
|
price: 3
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const defaultVectorModels = [
|
||||||
|
{
|
||||||
|
model: 'text-embedding-ada-002',
|
||||||
|
name: 'Embedding-2',
|
||||||
|
price: 0.2
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
export async function getInitConfig() {
|
export async function getInitConfig() {
|
||||||
try {
|
try {
|
||||||
const res = JSON.parse(readFileSync('data/config.json', 'utf-8'));
|
const res = JSON.parse(readFileSync('data/config.json', 'utf-8'));
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
|
||||||
global.systemEnv = res.SystemParams;
|
global.systemEnv = res.SystemParams || defaultSystemEnv;
|
||||||
global.feConfigs = res.FeConfig;
|
global.feConfigs = res.FeConfig || defaultFeConfigs;
|
||||||
global.chatModels = res.ChatModels;
|
global.chatModels = res.ChatModels || defaultChatModels;
|
||||||
global.qaModels = res.QAModels;
|
global.qaModels = res.QAModels || defaultQAModels;
|
||||||
global.vectorModels = res.VectorModels;
|
global.vectorModels = res.VectorModels || defaultVectorModels;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setDefaultData();
|
setDefaultData();
|
||||||
return Promise.reject('get init config error');
|
return Promise.reject('get init config error');
|
||||||
@@ -48,60 +105,9 @@ export async function getInitConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setDefaultData() {
|
export function setDefaultData() {
|
||||||
global.systemEnv = {
|
global.systemEnv = defaultSystemEnv;
|
||||||
vectorMaxProcess: 15,
|
global.feConfigs = defaultFeConfigs;
|
||||||
qaMaxProcess: 15,
|
global.chatModels = defaultChatModels;
|
||||||
pgIvfflatProbe: 20,
|
global.qaModels = defaultQAModels;
|
||||||
sensitiveCheck: false
|
global.vectorModels = defaultVectorModels;
|
||||||
};
|
|
||||||
global.feConfigs = {
|
|
||||||
show_emptyChat: true,
|
|
||||||
show_register: true,
|
|
||||||
show_appStore: true,
|
|
||||||
show_userDetail: true,
|
|
||||||
show_git: true,
|
|
||||||
systemTitle: 'FastAI',
|
|
||||||
authorText: 'Made by FastAI Team.'
|
|
||||||
};
|
|
||||||
global.chatModels = [
|
|
||||||
{
|
|
||||||
model: 'gpt-3.5-turbo',
|
|
||||||
name: 'FastAI-4k',
|
|
||||||
contextMaxToken: 4000,
|
|
||||||
quoteMaxToken: 2400,
|
|
||||||
maxTemperature: 1.2,
|
|
||||||
price: 1.5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
model: 'gpt-3.5-turbo-16k',
|
|
||||||
name: 'FastAI-16k',
|
|
||||||
contextMaxToken: 16000,
|
|
||||||
quoteMaxToken: 8000,
|
|
||||||
maxTemperature: 1.2,
|
|
||||||
price: 3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
model: 'gpt-4',
|
|
||||||
name: 'FastAI-Plus',
|
|
||||||
contextMaxToken: 8000,
|
|
||||||
quoteMaxToken: 4000,
|
|
||||||
maxTemperature: 1.2,
|
|
||||||
price: 45
|
|
||||||
}
|
|
||||||
];
|
|
||||||
global.qaModels = [
|
|
||||||
{
|
|
||||||
model: 'gpt-3.5-turbo-16k',
|
|
||||||
name: 'FastAI-16k',
|
|
||||||
maxToken: 16000,
|
|
||||||
price: 3
|
|
||||||
}
|
|
||||||
];
|
|
||||||
global.vectorModels = [
|
|
||||||
{
|
|
||||||
model: 'text-embedding-ada-002',
|
|
||||||
name: 'Embedding-2',
|
|
||||||
price: 0.2
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user