Commit 650a9dd6 by archer

fix: 生成词向量代理

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