Commit e4aeee7b by archer

perf: token count

parent 8036ed61
...@@ -76,14 +76,17 @@ export async function pushDataToKb({ ...@@ -76,14 +76,17 @@ export async function pushDataToKb({
data.forEach((item) => { data.forEach((item) => {
const text = item.q + item.a; const text = item.q + item.a;
if (mode === TrainingModeEnum.qa) {
// count token // count token
const token = modelToolMap[OpenAiChatEnum.GPT35].countTokens({ const token = modelToolMap[OpenAiChatEnum.GPT35].countTokens({
messages: [{ obj: 'System', value: item.q }] messages: [{ obj: 'System', value: item.q }]
}); });
if (token > modeMaxToken[TrainingModeEnum.qa]) {
return;
}
}
if (mode === TrainingModeEnum.qa && token > modeMaxToken[TrainingModeEnum.qa]) { if (!set.has(text)) {
console.log('q is too long');
} else if (!set.has(text)) {
filterData.push(item); filterData.push(item);
set.add(text); set.add(text);
} }
......
...@@ -40,6 +40,7 @@ const Detail = ({ kbId }: { kbId: string }) => { ...@@ -40,6 +40,7 @@ const Detail = ({ kbId }: { kbId: string }) => {
onSuccess(res) { onSuccess(res) {
kbId && setLastKbId(kbId); kbId && setLastKbId(kbId);
if (res) { if (res) {
setCurrentTab(TabEnum.data);
reset(res); reset(res);
BasicInfo.current?.initInput?.(res.tags); BasicInfo.current?.initInput?.(res.tags);
} }
......
...@@ -12,9 +12,9 @@ export const connectPg = async () => { ...@@ -12,9 +12,9 @@ export const connectPg = async () => {
user: process.env.PG_USER, user: process.env.PG_USER,
password: process.env.PG_PASSWORD, password: process.env.PG_PASSWORD,
database: process.env.PG_DB_NAME, database: process.env.PG_DB_NAME,
max: 80, max: global.systemEnv.vectorMaxProcess + 10,
idleTimeoutMillis: 60000, idleTimeoutMillis: 30000,
connectionTimeoutMillis: 20000 connectionTimeoutMillis: 5000
}); });
global.pgClient.on('error', (err) => { global.pgClient.on('error', (err) => {
......
...@@ -24,7 +24,7 @@ export const claudChat = async ({ apiKey, messages, stream, chatId }: ChatComple ...@@ -24,7 +24,7 @@ export const claudChat = async ({ apiKey, messages, stream, chatId }: ChatComple
headers: { headers: {
Authorization: apiKey Authorization: apiKey
}, },
timeout: stream ? 60000 : 240000, timeout: stream ? 60000 : 480000,
responseType: stream ? 'stream' : 'json' responseType: stream ? 'stream' : 'json'
} }
); );
......
...@@ -42,7 +42,7 @@ export const chatResponse = async ({ ...@@ -42,7 +42,7 @@ export const chatResponse = async ({
stop: ['.!?。'] stop: ['.!?。']
}, },
{ {
timeout: stream ? 60000 : 240000, timeout: stream ? 60000 : 480000,
responseType: stream ? 'stream' : 'json', responseType: stream ? 'stream' : 'json',
...axiosConfig(apiKey) ...axiosConfig(apiKey)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment