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
837c132d
authored
Mar 31, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 删除模型数据
parent
8239c584
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
21 deletions
+54
-21
src/pages/api/model/data/delModelDataById.ts
+15
-0
src/pages/api/model/del.ts
+20
-1
src/pages/model/detail/components/ModelDataCard.tsx
+1
-1
src/service/events/generateQA.ts
+17
-18
src/service/events/generateVector.ts
+1
-1
No files found.
src/pages/api/model/data/delModelDataById.ts
View file @
837c132d
...
@@ -2,6 +2,8 @@ import type { NextApiRequest, NextApiResponse } from 'next';
...
@@ -2,6 +2,8 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ModelData
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
ModelData
}
from
'@/service/mongo'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
{
connectRedis
}
from
'@/service/redis'
;
import
{
VecModelDataIndex
}
from
'@/constants/redis'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
...
@@ -22,14 +24,27 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -22,14 +24,27 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const
userId
=
await
authToken
(
authorization
);
const
userId
=
await
authToken
(
authorization
);
await
connectToDatabase
();
await
connectToDatabase
();
const
redis
=
await
connectRedis
();
const
data
=
await
ModelData
.
findById
(
dataId
);
await
ModelData
.
deleteOne
({
await
ModelData
.
deleteOne
({
_id
:
dataId
,
_id
:
dataId
,
userId
userId
});
});
// 删除 redis 数据
data
?.
q
.
forEach
(
async
(
item
)
=>
{
try
{
await
redis
.
json
.
del
(
`
${
VecModelDataIndex
}
:
${
item
.
id
}
`
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
});
jsonRes
(
res
);
jsonRes
(
res
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
error
:
err
error
:
err
...
...
src/pages/api/model/del.ts
View file @
837c132d
...
@@ -6,6 +6,8 @@ import { TrainingStatusEnum } from '@/constants/model';
...
@@ -6,6 +6,8 @@ import { TrainingStatusEnum } from '@/constants/model';
import
{
getOpenAIApi
}
from
'@/service/utils/chat'
;
import
{
getOpenAIApi
}
from
'@/service/utils/chat'
;
import
{
TrainingItemType
}
from
'@/types/training'
;
import
{
TrainingItemType
}
from
'@/types/training'
;
import
{
httpsAgent
}
from
'@/service/utils/tools'
;
import
{
httpsAgent
}
from
'@/service/utils/tools'
;
import
{
connectRedis
}
from
'@/service/redis'
;
import
{
VecModelDataIndex
}
from
'@/constants/redis'
;
/* 获取我的模型 */
/* 获取我的模型 */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
...
@@ -25,6 +27,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -25,6 +27,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const
userId
=
await
authToken
(
authorization
);
const
userId
=
await
authToken
(
authorization
);
await
connectToDatabase
();
await
connectToDatabase
();
const
redis
=
await
connectRedis
();
const
modelDataList
=
await
ModelData
.
find
({
modelId
});
// 删除 redis
modelDataList
?.
forEach
((
modelData
)
=>
modelData
.
q
.
forEach
(
async
(
item
)
=>
{
try
{
await
redis
.
json
.
del
(
`
${
VecModelDataIndex
}
:
${
item
.
id
}
`
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
})
);
let
requestQueue
:
any
[]
=
[];
let
requestQueue
:
any
[]
=
[];
// 删除对应的聊天
// 删除对应的聊天
...
@@ -73,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -73,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
userId
userId
})
})
);
);
await
requestQueue
;
await
Promise
.
all
(
requestQueue
);
jsonRes
(
res
);
jsonRes
(
res
);
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
src/pages/model/detail/components/ModelDataCard.tsx
View file @
837c132d
...
@@ -172,7 +172,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
...
@@ -172,7 +172,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
aria
-
label=
{
'delete'
}
aria
-
label=
{
'delete'
}
size=
{
'sm'
}
size=
{
'sm'
}
onClick=
{
async
()
=>
{
onClick=
{
async
()
=>
{
delOneModelData
(
item
.
_id
);
await
delOneModelData
(
item
.
_id
);
refetchData
(
pageNum
);
refetchData
(
pageNum
);
}
}
}
}
/>
/>
...
...
src/service/events/generateQA.ts
View file @
837c132d
...
@@ -29,9 +29,6 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -29,9 +29,6 @@ export async function generateQA(next = false): Promise<any> {
return
;
return
;
}
}
// 弹出文本
await
SplitData
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
$pop
:
{
textList
:
1
}
});
const
text
=
dataItem
.
textList
[
dataItem
.
textList
.
length
-
1
];
const
text
=
dataItem
.
textList
[
dataItem
.
textList
.
length
-
1
];
if
(
!
text
)
{
if
(
!
text
)
{
throw
new
Error
(
'无文本'
);
throw
new
Error
(
'无文本'
);
...
@@ -83,21 +80,23 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -83,21 +80,23 @@ export async function generateQA(next = false): Promise<any> {
result
:
splitText
(
res
?.
data
.
choices
[
0
].
message
?.
content
||
''
)
result
:
splitText
(
res
?.
data
.
choices
[
0
].
message
?.
content
||
''
)
}));
// 从 content 中提取 QA
}));
// 从 content 中提取 QA
// 插入 modelData 表,生成向量
await
Promise
.
allSettled
([
await
ModelData
.
insertMany
(
SplitData
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
$pop
:
{
textList
:
1
}
}),
response
.
result
.
map
((
item
)
=>
({
ModelData
.
insertMany
(
modelId
:
dataItem
.
modelId
,
response
.
result
.
map
((
item
)
=>
({
userId
:
dataItem
.
userId
,
modelId
:
dataItem
.
modelId
,
text
:
item
.
a
,
userId
:
dataItem
.
userId
,
q
:
[
text
:
item
.
a
,
{
q
:
[
id
:
nanoid
(),
{
text
:
item
.
q
id
:
nanoid
(),
}
text
:
item
.
q
],
}
status
:
1
],
}))
status
:
1
);
}))
)
]);
console
.
log
(
console
.
log
(
'生成QA成功,time:'
,
'生成QA成功,time:'
,
...
...
src/service/events/generateVector.ts
View file @
837c132d
...
@@ -48,7 +48,7 @@ export async function generateVector(next = false): Promise<any> {
...
@@ -48,7 +48,7 @@ export async function generateVector(next = false): Promise<any> {
.
then
((
vector
)
=>
.
then
((
vector
)
=>
redis
.
sendCommand
([
redis
.
sendCommand
([
'JSON.SET'
,
'JSON.SET'
,
`
${
VecModelDataIndex
}
:
${
dataId
}
:
${
i
}
`
,
`
${
VecModelDataIndex
}
:
${
item
.
id
}
`
,
'$'
,
'$'
,
JSON
.
stringify
({
JSON
.
stringify
({
dataId
,
dataId
,
...
...
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