perf: chat source

This commit is contained in:
archer
2023-07-26 16:15:21 +08:00
parent c06a9fb52b
commit bf2310cc29
2 changed files with 69 additions and 61 deletions

View File

@@ -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'

View File

@@ -31,30 +31,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}); });
} }
export async function getInitConfig() { const defaultSystemEnv = {
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) {
setDefaultData();
return Promise.reject('get init config error');
}
}
export function setDefaultData() {
global.systemEnv = {
vectorMaxProcess: 15, vectorMaxProcess: 15,
qaMaxProcess: 15, qaMaxProcess: 15,
pgIvfflatProbe: 20, pgIvfflatProbe: 20,
sensitiveCheck: false sensitiveCheck: false
}; };
global.feConfigs = { const defaultFeConfigs = {
show_emptyChat: true, show_emptyChat: true,
show_register: true, show_register: true,
show_appStore: true, show_appStore: true,
@@ -63,7 +46,7 @@ export function setDefaultData() {
systemTitle: 'FastAI', systemTitle: 'FastAI',
authorText: 'Made by FastAI Team.' authorText: 'Made by FastAI Team.'
}; };
global.chatModels = [ const defaultChatModels = [
{ {
model: 'gpt-3.5-turbo', model: 'gpt-3.5-turbo',
name: 'FastAI-4k', name: 'FastAI-4k',
@@ -89,7 +72,7 @@ export function setDefaultData() {
price: 45 price: 45
} }
]; ];
global.qaModels = [ const defaultQAModels = [
{ {
model: 'gpt-3.5-turbo-16k', model: 'gpt-3.5-turbo-16k',
name: 'FastAI-16k', name: 'FastAI-16k',
@@ -97,11 +80,34 @@ export function setDefaultData() {
price: 3 price: 3
} }
]; ];
global.vectorModels = [ const defaultVectorModels = [
{ {
model: 'text-embedding-ada-002', model: 'text-embedding-ada-002',
name: 'Embedding-2', name: 'Embedding-2',
price: 0.2 price: 0.2
} }
]; ];
export async function getInitConfig() {
try {
const res = JSON.parse(readFileSync('data/config.json', 'utf-8'));
console.log(res);
global.systemEnv = res.SystemParams || defaultSystemEnv;
global.feConfigs = res.FeConfig || defaultFeConfigs;
global.chatModels = res.ChatModels || defaultChatModels;
global.qaModels = res.QAModels || defaultQAModels;
global.vectorModels = res.VectorModels || defaultVectorModels;
} catch (error) {
setDefaultData();
return Promise.reject('get init config error');
}
}
export function setDefaultData() {
global.systemEnv = defaultSystemEnv;
global.feConfigs = defaultFeConfigs;
global.chatModels = defaultChatModels;
global.qaModels = defaultQAModels;
global.vectorModels = defaultVectorModels;
} }