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';
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
ModelData
}
from
'@/service/mongo'
;
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
>
)
{
try
{
...
...
@@ -22,14 +24,27 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const
userId
=
await
authToken
(
authorization
);
await
connectToDatabase
();
const
redis
=
await
connectRedis
();
const
data
=
await
ModelData
.
findById
(
dataId
);
await
ModelData
.
deleteOne
({
_id
:
dataId
,
userId
});
// 删除 redis 数据
data
?.
q
.
forEach
(
async
(
item
)
=>
{
try
{
await
redis
.
json
.
del
(
`
${
VecModelDataIndex
}
:
${
item
.
id
}
`
);
}
catch
(
error
)
{
console
.
log
(
error
);
}
});
jsonRes
(
res
);
}
catch
(
err
)
{
console
.
log
(
err
);
jsonRes
(
res
,
{
code
:
500
,
error
:
err
...
...
src/pages/api/model/del.ts
View file @
837c132d
...
...
@@ -6,6 +6,8 @@ import { TrainingStatusEnum } from '@/constants/model';
import
{
getOpenAIApi
}
from
'@/service/utils/chat'
;
import
{
TrainingItemType
}
from
'@/types/training'
;
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
>
)
{
...
...
@@ -25,6 +27,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const
userId
=
await
authToken
(
authorization
);
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
[]
=
[];
// 删除对应的聊天
...
...
@@ -73,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
userId
})
);
await
requestQueue
;
await
Promise
.
all
(
requestQueue
);
jsonRes
(
res
);
}
catch
(
err
)
{
...
...
src/pages/model/detail/components/ModelDataCard.tsx
View file @
837c132d
...
...
@@ -172,7 +172,7 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
aria
-
label=
{
'delete'
}
size=
{
'sm'
}
onClick=
{
async
()
=>
{
delOneModelData
(
item
.
_id
);
await
delOneModelData
(
item
.
_id
);
refetchData
(
pageNum
);
}
}
/>
...
...
src/service/events/generateQA.ts
View file @
837c132d
...
...
@@ -29,9 +29,6 @@ export async function generateQA(next = false): Promise<any> {
return
;
}
// 弹出文本
await
SplitData
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
$pop
:
{
textList
:
1
}
});
const
text
=
dataItem
.
textList
[
dataItem
.
textList
.
length
-
1
];
if
(
!
text
)
{
throw
new
Error
(
'无文本'
);
...
...
@@ -83,21 +80,23 @@ export async function generateQA(next = false): Promise<any> {
result
:
splitText
(
res
?.
data
.
choices
[
0
].
message
?.
content
||
''
)
}));
// 从 content 中提取 QA
// 插入 modelData 表,生成向量
await
ModelData
.
insertMany
(
response
.
result
.
map
((
item
)
=>
({
modelId
:
dataItem
.
modelId
,
userId
:
dataItem
.
userId
,
text
:
item
.
a
,
q
:
[
{
id
:
nanoid
(),
text
:
item
.
q
}
],
status
:
1
}))
);
await
Promise
.
allSettled
([
SplitData
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
$pop
:
{
textList
:
1
}
}),
ModelData
.
insertMany
(
response
.
result
.
map
((
item
)
=>
({
modelId
:
dataItem
.
modelId
,
userId
:
dataItem
.
userId
,
text
:
item
.
a
,
q
:
[
{
id
:
nanoid
(),
text
:
item
.
q
}
],
status
:
1
}))
)
]);
console
.
log
(
'生成QA成功,time:'
,
...
...
src/service/events/generateVector.ts
View file @
837c132d
...
...
@@ -48,7 +48,7 @@ export async function generateVector(next = false): Promise<any> {
.
then
((
vector
)
=>
redis
.
sendCommand
([
'JSON.SET'
,
`
${
VecModelDataIndex
}
:
${
dataId
}
:
${
i
}
`
,
`
${
VecModelDataIndex
}
:
${
item
.
id
}
`
,
'$'
,
JSON
.
stringify
({
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