perf: token count

This commit is contained in:
archer
2023-06-14 20:02:43 +08:00
parent 8036ed6143
commit e4aeee7be3
5 changed files with 16 additions and 12 deletions

View File

@@ -76,14 +76,17 @@ export async function pushDataToKb({
data.forEach((item) => {
const text = item.q + item.a;
// count token
const token = modelToolMap[OpenAiChatEnum.GPT35].countTokens({
messages: [{ obj: 'System', value: item.q }]
});
if (mode === TrainingModeEnum.qa) {
// count token
const token = modelToolMap[OpenAiChatEnum.GPT35].countTokens({
messages: [{ obj: 'System', value: item.q }]
});
if (token > modeMaxToken[TrainingModeEnum.qa]) {
return;
}
}
if (mode === TrainingModeEnum.qa && token > modeMaxToken[TrainingModeEnum.qa]) {
console.log('q is too long');
} else if (!set.has(text)) {
if (!set.has(text)) {
filterData.push(item);
set.add(text);
}

View File

@@ -40,6 +40,7 @@ const Detail = ({ kbId }: { kbId: string }) => {
onSuccess(res) {
kbId && setLastKbId(kbId);
if (res) {
setCurrentTab(TabEnum.data);
reset(res);
BasicInfo.current?.initInput?.(res.tags);
}

View File

@@ -12,9 +12,9 @@ export const connectPg = async () => {
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DB_NAME,
max: 80,
idleTimeoutMillis: 60000,
connectionTimeoutMillis: 20000
max: global.systemEnv.vectorMaxProcess + 10,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 5000
});
global.pgClient.on('error', (err) => {

View File

@@ -24,7 +24,7 @@ export const claudChat = async ({ apiKey, messages, stream, chatId }: ChatComple
headers: {
Authorization: apiKey
},
timeout: stream ? 60000 : 240000,
timeout: stream ? 60000 : 480000,
responseType: stream ? 'stream' : 'json'
}
);

View File

@@ -42,7 +42,7 @@ export const chatResponse = async ({
stop: ['.!?。']
},
{
timeout: stream ? 60000 : 240000,
timeout: stream ? 60000 : 480000,
responseType: stream ? 'stream' : 'json',
...axiosConfig(apiKey)
}