Commit 650a9dd6 by archer

fix: 生成词向量代理

parent 42e12d7d
......@@ -11,7 +11,6 @@
"format": "prettier --config \"./.prettierrc.js\" --write \"./src/**/*.{ts,tsx,scss}\""
},
"dependencies": {
"@alicloud/alinlp20200629": "^2.0.2",
"@chakra-ui/icons": "^2.0.17",
"@chakra-ui/react": "^2.5.1",
"@emotion/react": "^11.10.6",
......
......@@ -84,21 +84,25 @@ export async function generateAbstract(next = false): Promise<any> {
// 生成词向量
const vectorResponse = await Promise.allSettled(
splitContents.map((item) =>
chatAPI.createEmbedding({
model: 'text-embedding-ada-002',
input: item.abstract
})
chatAPI.createEmbedding(
{
model: 'text-embedding-ada-002',
input: item.abstract
},
{
timeout: 120000,
httpsAgent
}
)
)
);
// 筛选成功的向量请求
const vectorSuccessResponse = vectorResponse
.map((item: any, i) => {
if (item.status !== 'fulfilled') {
// 没有词向量的【摘要】不要
console.log('获取词向量错误: ', item);
return {
abstract: splitContents[i].abstract,
abstractVector: []
};
return '';
}
return {
abstract: splitContents[i].abstract,
......@@ -120,7 +124,7 @@ export async function generateAbstract(next = false): Promise<any> {
// 计费
!userApiKey &&
splitContents.length > 0 &&
vectorSuccessResponse.length > 0 &&
pushSplitDataBill({
userId: dataItem.userId,
type: 'abstract',
......@@ -128,13 +132,13 @@ export async function generateAbstract(next = false): Promise<any> {
systemPrompt.content +
dataItem.text +
rawContent +
rawContent.substring(0, Math.floor(dataItem.text.length / 10)) // 向量价格是gpt35的1/10
rawContent.substring(0, Math.floor(dataItem.text.length / 10)) // 向量价格是 gpt35 的1/10
});
console.log(
'生成摘要成功,time:',
`${(Date.now() - startTime) / 1000}s`,
'摘要数量:',
splitContents.length
vectorSuccessResponse.length
);
} catch (error: any) {
console.log('error: 生成摘要错误', dataItem?._id);
......
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