perf: kb-add last question to search

This commit is contained in:
archer
2023-05-03 18:38:59 +08:00
parent e384893ae0
commit 17a42ac0cc
7 changed files with 81 additions and 42 deletions

View File

@@ -22,12 +22,12 @@ export const openaiCreateEmbedding = async ({
userApiKey,
systemApiKey,
userId,
text
textArr
}: {
userApiKey?: string;
systemApiKey: string;
userId: string;
text: string;
textArr: string[];
}) => {
// 获取 chatAPI
const chatAPI = getOpenAIApi(userApiKey || systemApiKey);
@@ -37,7 +37,7 @@ export const openaiCreateEmbedding = async ({
.createEmbedding(
{
model: embeddingModel,
input: text
input: textArr
},
{
timeout: 60000,
@@ -46,18 +46,18 @@ export const openaiCreateEmbedding = async ({
)
.then((res) => ({
tokenLen: res.data.usage.total_tokens || 0,
vector: res.data.data?.[0]?.embedding || []
vectors: res.data.data.map((item) => item.embedding)
}));
pushGenerateVectorBill({
isPay: !userApiKey,
userId,
text,
text: textArr.join(''),
tokenLen: res.tokenLen
});
return {
vector: res.vector,
vectors: res.vectors,
chatAPI
};
};