From 9a0c92629b7f891c4fdddee2e3bffd2c164986cc Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Fri, 12 May 2023 23:24:25 +0800 Subject: [PATCH] perf: token params --- src/service/plugins/searchKb.ts | 7 ++++++- src/service/utils/chat/claude.ts | 2 +- src/service/utils/chat/openai.ts | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/service/plugins/searchKb.ts b/src/service/plugins/searchKb.ts index f21b71172..00159f9c5 100644 --- a/src/service/plugins/searchKb.ts +++ b/src/service/plugins/searchKb.ts @@ -29,6 +29,11 @@ export const searchKb = async ({ }[]; }> => { async function search(textArr: string[] = []) { + const limitMap: Record = { + [ModelVectorSearchModeEnum.hightSimilarity]: 15, + [ModelVectorSearchModeEnum.noContext]: 15, + [ModelVectorSearchModeEnum.lowSimilarity]: 20 + }; // 获取提示词的向量 const { vectors: promptVectors } = await openaiCreateEmbedding({ userOpenAiKey, @@ -48,7 +53,7 @@ export const searchKb = async ({ `vector <=> '[${promptVector}]' < ${similarity}` ], order: [{ field: 'vector', mode: `<=> '[${promptVector}]'` }], - limit: 20 + limit: limitMap[model.chat.searchMode] }).then((res) => res.rows) ) ); diff --git a/src/service/utils/chat/claude.ts b/src/service/utils/chat/claude.ts index e5c46f82c..95ae5dbdb 100644 --- a/src/service/utils/chat/claude.ts +++ b/src/service/utils/chat/claude.ts @@ -40,7 +40,7 @@ export const lafClaudChat = async ({ headers: { Authorization: apiKey }, - timeout: stream ? 40000 : 240000, + timeout: stream ? 60000 : 240000, responseType: stream ? 'stream' : 'json' } ); diff --git a/src/service/utils/chat/openai.ts b/src/service/utils/chat/openai.ts index 4aec0548d..4ee556b93 100644 --- a/src/service/utils/chat/openai.ts +++ b/src/service/utils/chat/openai.ts @@ -73,7 +73,7 @@ export const chatResponse = async ({ const filterMessages = ChatContextFilter({ model, prompts: messages, - maxTokens: Math.ceil(ChatModelMap[model].contextMaxToken * 0.9) + maxTokens: Math.ceil(ChatModelMap[model].contextMaxToken * 0.85) }); const adaptMessages = adaptChatItem_openAI({ messages: filterMessages }); @@ -90,7 +90,7 @@ export const chatResponse = async ({ stop: ['.!?。'] }, { - timeout: stream ? 40000 : 240000, + timeout: stream ? 60000 : 240000, responseType: stream ? 'stream' : 'json', ...axiosConfig() }