Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
7e544211
authored
Apr 17, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 多机部署,导致任务重复
parent
647f7016
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
4 deletions
+49
-4
src/pages/api/openapi/startEvents.ts
+19
-0
src/service/events/generateAbstract.ts
+5
-0
src/service/events/generateQA.ts
+12
-2
src/service/events/generateVector.ts
+13
-2
No files found.
src/pages/api/openapi/startEvents.ts
0 → 100644
View file @
7e544211
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
generateQA
}
from
'@/service/events/generateQA'
;
import
{
generateVector
}
from
'@/service/events/generateVector'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
generateQA
();
generateVector
();
jsonRes
(
res
);
}
catch
(
err
)
{
jsonRes
(
res
,
{
code
:
500
,
error
:
err
});
}
}
src/service/events/generateAbstract.ts
View file @
7e544211
...
@@ -8,7 +8,12 @@ import { ChatModelNameEnum } from '@/constants/model';
...
@@ -8,7 +8,12 @@ import { ChatModelNameEnum } from '@/constants/model';
import
{
pushSplitDataBill
}
from
'@/service/events/pushBill'
;
import
{
pushSplitDataBill
}
from
'@/service/events/pushBill'
;
export
async
function
generateAbstract
(
next
=
false
):
Promise
<
any
>
{
export
async
function
generateAbstract
(
next
=
false
):
Promise
<
any
>
{
if
(
process
.
env
.
queueTask
!==
'1'
)
{
fetch
(
process
.
env
.
parentUrl
||
''
);
return
;
}
if
(
global
.
generatingAbstract
&&
!
next
)
return
;
if
(
global
.
generatingAbstract
&&
!
next
)
return
;
global
.
generatingAbstract
=
true
;
global
.
generatingAbstract
=
true
;
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
...
...
src/service/events/generateQA.ts
View file @
7e544211
...
@@ -13,7 +13,12 @@ import { ModelSplitDataSchema } from '@/types/mongoSchema';
...
@@ -13,7 +13,12 @@ import { ModelSplitDataSchema } from '@/types/mongoSchema';
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
12
);
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
12
);
export
async
function
generateQA
(
next
=
false
):
Promise
<
any
>
{
export
async
function
generateQA
(
next
=
false
):
Promise
<
any
>
{
if
(
process
.
env
.
queueTask
!==
'1'
)
{
fetch
(
process
.
env
.
parentUrl
||
''
);
return
;
}
if
(
global
.
generatingQA
===
true
&&
!
next
)
return
;
if
(
global
.
generatingQA
===
true
&&
!
next
)
return
;
global
.
generatingQA
=
true
;
global
.
generatingQA
=
true
;
let
dataId
=
null
;
let
dataId
=
null
;
...
@@ -165,8 +170,13 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -165,8 +170,13 @@ export async function generateQA(next = false): Promise<any> {
console
.
log
(
'生成QA错误:'
,
error
);
console
.
log
(
'生成QA错误:'
,
error
);
}
}
if
(
dataId
&&
error
?.
response
?.
data
?.
error
?.
type
===
'insufficient_quota'
)
{
// 没有余额或者凭证错误时,拒绝任务
console
.
log
(
'api 余额不足'
);
if
(
dataId
&&
(
+
error
.
response
?.
status
===
401
||
error
?.
response
?.
data
?.
error
?.
type
===
'insufficient_quota'
)
)
{
console
.
log
(
'api 异常,删除QA任务'
);
await
SplitData
.
findByIdAndUpdate
(
dataId
,
{
await
SplitData
.
findByIdAndUpdate
(
dataId
,
{
textList
:
[],
textList
:
[],
...
...
src/service/events/generateVector.ts
View file @
7e544211
...
@@ -5,7 +5,13 @@ import { ModelDataStatusEnum } from '@/constants/redis';
...
@@ -5,7 +5,13 @@ import { ModelDataStatusEnum } from '@/constants/redis';
import
{
openaiCreateEmbedding
,
getOpenApiKey
}
from
'../utils/openai'
;
import
{
openaiCreateEmbedding
,
getOpenApiKey
}
from
'../utils/openai'
;
export
async
function
generateVector
(
next
=
false
):
Promise
<
any
>
{
export
async
function
generateVector
(
next
=
false
):
Promise
<
any
>
{
if
(
process
.
env
.
queueTask
!==
'1'
)
{
fetch
(
process
.
env
.
parentUrl
||
''
);
return
;
}
if
(
global
.
generatingVector
&&
!
next
)
return
;
if
(
global
.
generatingVector
&&
!
next
)
return
;
global
.
generatingVector
=
true
;
global
.
generatingVector
=
true
;
let
dataId
=
null
;
let
dataId
=
null
;
try
{
try
{
...
@@ -84,8 +90,13 @@ export async function generateVector(next = false): Promise<any> {
...
@@ -84,8 +90,13 @@ export async function generateVector(next = false): Promise<any> {
console
.
log
(
'生成向量错误:'
,
error
);
console
.
log
(
'生成向量错误:'
,
error
);
}
}
if
(
dataId
&&
error
?.
response
?.
data
?.
error
?.
type
===
'insufficient_quota'
)
{
// 没有余额或者凭证错误时,拒绝任务
console
.
log
(
'api 余额不足,删除 redis 模型数据'
);
if
(
dataId
&&
(
+
error
.
response
?.
status
===
401
||
error
?.
response
?.
data
?.
error
?.
type
===
'insufficient_quota'
)
)
{
console
.
log
(
'删除向量生成任务记录'
);
const
redis
=
await
connectRedis
();
const
redis
=
await
connectRedis
();
redis
.
del
(
dataId
);
redis
.
del
(
dataId
);
generateVector
(
true
);
generateVector
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment