Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
db_gpt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
linyangyang
db_gpt
Commits
8d30c816
Commit
8d30c816
authored
Sep 14, 2024
by
于飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加敏感词的时候,加入过滤列表中
parent
234a6ad2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
crud.py
dbgpt/app/apps/vadmin/word/crud.py
+9
-0
views.py
dbgpt/app/apps/vadmin/word/views.py
+16
-2
No files found.
dbgpt/app/apps/vadmin/word/crud.py
View file @
8d30c816
...
...
@@ -143,6 +143,15 @@ class SensitiveDal(DalBase):
"""
return
list
(
queryset
.
all
())
async
def
get_sensitive_byid
(
self
,
uid
:
int
)
->
Any
:
sql
=
select
(
models
.
sensitive
.
VadminWordSensitive
)
.
where
(
models
.
sensitive
.
VadminWordSensitive
.
id
==
uid
)
queryset
=
await
self
.
db
.
scalars
(
sql
)
"""
for row in dataqs:
print(f"编号:{row.id} 词条:{row.word_name} ")
"""
return
queryset
.
first
()
async
def
update_sensitives
(
self
,
ids
:
[],
data
:
SensitiveUpdate
):
"""
修改敏感词
...
...
dbgpt/app/apps/vadmin/word/views.py
View file @
8d30c816
...
...
@@ -14,7 +14,7 @@ from dbgpt.app.apps.vadmin.word.schemas.sensitive import SensitiveSchemas, Sensi
from
dbgpt.app.apps.vadmin.word.params.sensitive
import
SensitiveParams
from
dbgpt.app.apps.vadmin.word
import
crud
from
fastapi.encoders
import
jsonable_encoder
from
dbgpt.app.apps.utils.filter
import
mydfafiter
,
mydfafiter_picture
,
mydfafiter_question
,
mydfafiter_video
from
...core.dependencies
import
IdList
router
=
APIRouter
()
...
...
@@ -82,6 +82,10 @@ async def create_sensitive(qdata: Request, auth: Auth = Depends(FullAdminAuth())
Sensit_data
=
SensitiveSchemas
()
Sensit_data
.
word_name
=
qdata
.
query_params
[
'word_name'
]
# 向敏感词字典中新加一条敏感词
mydfafiter
.
add
(
Sensit_data
.
word_name
)
return
SuccessResponse
(
await
crud
.
SensitiveDal
(
auth
.
db
)
.
create_data
(
data
=
Sensit_data
))
@
router
.
get
(
"/get_sensitives"
,
summary
=
"获取敏感词列表"
)
...
...
@@ -103,10 +107,16 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut
print
(
f
"word_id:{data.query_params['id']} req词条:{data.query_params['word_name']} "
)
data_id
=
data
.
query_params
[
'id'
]
sdata
=
SensitiveUpdate
sdata
.
word_name
=
data
.
query_params
[
'word_name'
]
sensitive_datas
=
await
crud
.
SensitiveDal
(
auth
.
db
)
.
get_sensitive_byid
(
data_id
)
if
sensitive_datas
!=
None
:
print
(
f
"------编辑时要删除旧的敏感词------>:{sensitive_datas.word_name}"
)
mydfafiter
.
remove
(
sensitive_datas
.
word_name
)
print
(
f
"------编辑时要添加新的敏感词------>:{sdata.word_name}"
)
mydfafiter
.
add
(
sdata
.
word_name
)
sensitiveids
=
[]
sensitiveids
.
append
(
data_id
)
...
...
@@ -116,4 +126,8 @@ async def update_sensitive_byid(data: Request, auth: Auth = Depends(FullAdminAut
@
router
.
post
(
"/delete_sensitives"
,
summary
=
"根据id删除敏感词"
)
async
def
delete_sensitives
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
await
crud
.
SensitiveDal
(
auth
.
db
)
.
delete_datas
(
ids
=
ids
.
ids
,
v_soft
=
True
)
sensitive_datas
=
await
crud
.
SensitiveDal
(
auth
.
db
)
.
get_sensitive_byid
(
ids
.
ids
[
0
])
if
sensitive_datas
!=
None
:
print
(
f
"------要删除的敏感词------>:{sensitive_datas}"
)
mydfafiter
.
remove
(
sensitive_datas
.
word_name
)
return
SuccessResponse
(
"删除成功"
)
\ No newline at end of file
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