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
be3e97d4
Commit
be3e97d4
authored
Aug 15, 2024
by
于飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改近义词
parent
02a290c0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
102 deletions
+28
-102
crud.py
dbgpt/app/apps/vadmin/word/crud.py
+10
-25
sensitive.py
dbgpt/app/apps/vadmin/word/schemas/sensitive.py
+1
-3
views.py
dbgpt/app/apps/vadmin/word/views.py
+17
-74
No files found.
dbgpt/app/apps/vadmin/word/crud.py
View file @
be3e97d4
...
@@ -27,7 +27,7 @@ from dbgpt.app.apps.utils.tools import test_password
...
@@ -27,7 +27,7 @@ from dbgpt.app.apps.utils.tools import test_password
from
.
import
models
,
schemas
from
.
import
models
,
schemas
from
.params.similar
import
SimilarParams
from
.params.similar
import
SimilarParams
from
.schemas.similar
import
SimilarIn
,
SimilarUpdate
from
.schemas.similar
import
Similar
Schemas
,
Similar
In
,
SimilarUpdate
from
.schemas.sensitive
import
SensitiveIn
,
SensitiveUpdate
from
.schemas.sensitive
import
SensitiveIn
,
SensitiveUpdate
from
.models
import
sensitive
from
.models
import
sensitive
...
@@ -46,16 +46,7 @@ class SimilarDal(DalBase):
...
@@ -46,16 +46,7 @@ class SimilarDal(DalBase):
super
(
SimilarDal
,
self
)
.
__init__
()
super
(
SimilarDal
,
self
)
.
__init__
()
self
.
db
=
db
self
.
db
=
db
self
.
model
=
models
.
similar
.
VadminWordSimilar
self
.
model
=
models
.
similar
.
VadminWordSimilar
self
.
schema
=
schemas
.
similar
.
SimilarSchemas
self
.
schema
=
schemas
.
similar
.
SimilarInDic
async
def
get_similars
(
self
)
->
Any
:
sql
=
select
(
models
.
similar
.
VadminWordSimilar
)
.
where
(
models
.
similar
.
VadminWordSimilar
.
is_delete
==
false
())
queryset
=
await
self
.
db
.
scalars
(
sql
)
"""
for row in dataqs:
print(f"编号:{row.id} 词条:{row.word_name} 近义词:{row.similar_name} ")
"""
return
list
(
queryset
.
all
())
async
def
get_similar_byid
(
self
,
qid
):
async
def
get_similar_byid
(
self
,
qid
):
"""
"""
...
@@ -78,9 +69,9 @@ class SimilarDal(DalBase):
...
@@ -78,9 +69,9 @@ class SimilarDal(DalBase):
)
)
)
)
async
def
create_
similar_
data
(
async
def
create_data
(
self
,
self
,
data
:
Similar
In
,
data
:
Similar
Schemas
,
v_options
:
list
[
_AbstractLoad
]
=
None
,
v_options
:
list
[
_AbstractLoad
]
=
None
,
v_return_obj
:
bool
=
False
,
v_return_obj
:
bool
=
False
,
v_schema
:
Any
=
None
v_schema
:
Any
=
None
...
@@ -104,11 +95,8 @@ class SimilarDal(DalBase):
...
@@ -104,11 +95,8 @@ class SimilarDal(DalBase):
obj
.
word_name
=
data
.
word_name
obj
.
word_name
=
data
.
word_name
obj
.
similar_name
=
data
.
similar_name
obj
.
similar_name
=
data
.
similar_name
#await self.flush(obj)
await
self
.
flush
(
obj
)
#return await self.out_dict(obj, v_options, v_return_obj, v_schema)
return
await
self
.
out_dict
(
obj
,
v_options
,
v_return_obj
,
v_schema
)
self
.
db
.
add
(
obj
)
await
self
.
db
.
commit
()
return
None
class
SensitiveDal
(
DalBase
):
class
SensitiveDal
(
DalBase
):
...
@@ -116,9 +104,9 @@ class SensitiveDal(DalBase):
...
@@ -116,9 +104,9 @@ class SensitiveDal(DalBase):
super
(
SensitiveDal
,
self
)
.
__init__
()
super
(
SensitiveDal
,
self
)
.
__init__
()
self
.
db
=
db
self
.
db
=
db
self
.
model
=
models
.
sensitive
.
VadminWordSensitive
self
.
model
=
models
.
sensitive
.
VadminWordSensitive
self
.
schema
=
schemas
.
sensitive
.
Sensitive
Schemas
self
.
schema
=
schemas
.
sensitive
.
Sensitive
InDic
async
def
create_
sensitive_
data
(
async
def
create_data
(
self
,
self
,
data
:
SensitiveIn
,
data
:
SensitiveIn
,
v_options
:
list
[
_AbstractLoad
]
=
None
,
v_options
:
list
[
_AbstractLoad
]
=
None
,
...
@@ -143,11 +131,8 @@ class SensitiveDal(DalBase):
...
@@ -143,11 +131,8 @@ class SensitiveDal(DalBase):
obj
=
self
.
model
()
obj
=
self
.
model
()
obj
.
word_name
=
data
.
word_name
obj
.
word_name
=
data
.
word_name
#await self.flush(obj)
await
self
.
flush
(
obj
)
#return await self.out_dict(obj, v_options, v_return_obj, v_schema)
return
await
self
.
out_dict
(
obj
,
v_options
,
v_return_obj
,
v_schema
)
self
.
db
.
add
(
obj
)
await
self
.
db
.
commit
()
return
None
async
def
get_sensitives
(
self
)
->
Any
:
async
def
get_sensitives
(
self
)
->
Any
:
sql
=
select
(
models
.
sensitive
.
VadminWordSensitive
)
.
where
(
models
.
sensitive
.
VadminWordSensitive
.
is_delete
==
false
())
sql
=
select
(
models
.
sensitive
.
VadminWordSensitive
)
.
where
(
models
.
sensitive
.
VadminWordSensitive
.
is_delete
==
false
())
...
...
dbgpt/app/apps/vadmin/word/schemas/sensitive.py
View file @
be3e97d4
...
@@ -20,9 +20,7 @@ class SensitiveSchemas(BaseModel):
...
@@ -20,9 +20,7 @@ class SensitiveSchemas(BaseModel):
class
SensitiveInDic
(
SensitiveSchemas
):
class
SensitiveInDic
(
SensitiveSchemas
):
model_config
=
ConfigDict
(
from_attributes
=
True
)
model_config
=
ConfigDict
(
from_attributes
=
True
)
"""
创建近义词
"""
word_name
:
str
|
None
=
""
word_name
:
str
|
None
=
""
class
SensitiveIn
(
SensitiveSchemas
):
class
SensitiveIn
(
SensitiveSchemas
):
...
...
dbgpt/app/apps/vadmin/word/views.py
View file @
be3e97d4
...
@@ -23,10 +23,6 @@ router = APIRouter()
...
@@ -23,10 +23,6 @@ router = APIRouter()
###########################################################
###########################################################
@
router
.
get
(
"/get_similars"
,
summary
=
"获取同义词列表"
)
@
router
.
get
(
"/get_similars"
,
summary
=
"获取同义词列表"
)
async
def
get_similars
(
para
:
SimilarParams
=
Depends
(),
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
get_similars
(
para
:
SimilarParams
=
Depends
(),
auth
:
Auth
=
Depends
(
OpenAuth
())):
#datas = await crud.SimilarDal(auth.db).get_data(para)
#model = models.similar.VadminWordSimilar #不需要关联查询
#v_schema = schemas.similar.SimilarSchemas
v_schema
=
schemas
.
similar
.
SimilarInDic
v_schema
=
schemas
.
similar
.
SimilarInDic
datas
,
count
=
await
crud
.
SimilarDal
(
auth
.
db
)
.
get_datas
(
datas
,
count
=
await
crud
.
SimilarDal
(
auth
.
db
)
.
get_datas
(
**
para
.
dict
(),
**
para
.
dict
(),
...
@@ -35,49 +31,22 @@ async def get_similars(para: SimilarParams = Depends(), auth: Auth = Depends(Ope
...
@@ -35,49 +31,22 @@ async def get_similars(para: SimilarParams = Depends(), auth: Auth = Depends(Ope
)
)
return
SuccessResponse
(
datas
,
count
=
count
)
return
SuccessResponse
(
datas
,
count
=
count
)
"""
@router.get("/get_similars", summary="获取同义词列表")
async def get_similars(auth: Auth = Depends(OpenAuth())):
model = VadminWordSimilar
print(f"编号:{model.id} 近义词:{model.word_name}")
datas = await crud.SimilarDal(auth.db).get_similars()
jsondatas = jsonable_encoder(datas)
for row in datas:
print(f"编号:{row.id} 词条:{row.word_name} 近义词:{row.similar_name} ")
return SuccessResponse(jsondatas, count=1)
"""
@
router
.
post
(
"/create_similar"
,
summary
=
"创建同义词"
)
@
router
.
post
(
"/create_similar"
,
summary
=
"创建同义词"
)
async
def
create_similar
(
data
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
create_similar
(
qdata
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
#async def create_similar(data: SimilarIn, auth: Auth = Depends(FullAdminAuth(permissions=["auth.user.create"]))):
if
qdata
is
None
:
print
(
'create_similar is None'
)
if
data
is
None
:
print
(
'SimilarIn is None'
)
else
:
else
:
print
(
f
"req词条:{data.query_params['word_name']} req近义词:{data.query_params['similar_name']} "
)
print
(
f
"req词条:{qdata.query_params['word_name']} req近义词:{qdata.query_params['similar_name']} "
)
sdata
=
SimilarIn
()
sdata
.
word_name
=
data
.
query_params
[
'word_name'
]
sdata
.
similar_name
=
data
.
query_params
[
'similar_name'
]
sdata
.
is_delete
=
0
sdata
.
create_datetime
=
''
sdata
.
update_datetime
=
''
sdata
.
delete_datetime
=
''
await
crud
.
SimilarDal
(
auth
.
db
)
.
create_similar_data
(
data
=
sdata
)
simi_data
=
SimilarSchemas
(
)
simi_data
.
word_name
=
qdata
.
query_params
[
'word_name'
]
datas
=
[
]
simi_data
.
similar_name
=
qdata
.
query_params
[
'similar_name'
]
return
SuccessResponse
(
datas
,
count
=
1
)
return
SuccessResponse
(
await
crud
.
SimilarDal
(
auth
.
db
)
.
create_data
(
data
=
simi_data
)
)
@
router
.
post
(
"/delete_similars"
,
summary
=
"根据id删除同义词"
)
@
router
.
post
(
"/delete_similars"
,
summary
=
"根据id删除同义词"
)
async
def
delete_similars
(
data
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
delete_similars
(
data
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
if
data
is
None
:
if
data
is
None
:
print
(
'SimilarIn is None'
)
return
ErrorResponse
(
"删除同义词请求参数为空!"
)
return
ErrorResponse
(
"不能删除当前近义词"
)
else
:
print
(
f
"req词条:{data.query_params['word_name']} req近义词:{data.query_params['similar_name']} "
)
data_id
=
data
.
query_params
[
'word_id'
]
data_id
=
data
.
query_params
[
'word_id'
]
similarids
=
[
data_id
]
similarids
=
[
data_id
]
...
@@ -108,41 +77,15 @@ async def update_similar_byid(data: Request, auth: Auth = Depends(OpenAuth())):
...
@@ -108,41 +77,15 @@ async def update_similar_byid(data: Request, auth: Auth = Depends(OpenAuth())):
# 敏感词管理
# 敏感词管理
###########################################################
###########################################################
@
router
.
post
(
"/create_sensitive"
,
summary
=
"创建敏感词"
)
@
router
.
post
(
"/create_sensitive"
,
summary
=
"创建敏感词"
)
async
def
create_sensitive
(
req
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
create_sensitive
(
qdata
:
Request
,
auth
:
Auth
=
Depends
(
OpenAuth
())):
if
req
is
None
:
if
qdata
is
None
:
print
(
'SimilarIn is None'
)
print
(
'create_sensitive is None'
)
return
ErrorResponse
(
"不能创建当前敏感词"
)
else
:
else
:
print
(
f
"req词条:{req.query_params['word_name']} "
)
print
(
f
"req词条:{qdata.query_params['word_name']} "
)
"""
sdata = SensitiveSchemas()
sdata.word_name = req.query_params['word_name']
return SuccessResponse(await crud.SensitiveDal(auth.db).create_data(data=sdata))
"""
sdata
=
SensitiveIn
sdata
.
word_name
=
req
.
query_params
[
'word_name'
]
sdata
.
is_delete
=
0
sdata
.
create_datetime
=
''
sdata
.
update_datetime
=
''
sdata
.
delete_datetime
=
''
await
crud
.
SensitiveDal
(
auth
.
db
)
.
create_sensitive_data
(
data
=
sdata
)
return
SuccessResponse
(
"请求成功!"
)
"""
@router.get("/get_sensitives", summary="获取敏感词列表")
async def get_sensitives(auth: Auth = Depends(OpenAuth())):
datas = await crud.SensitiveDal(auth.db).get_sensitives()
jsondatas = jsonable_encoder(datas)
for row in datas:
Sensit_data
=
SensitiveSchemas
()
print(f"编号:{row.id} 词条:{row.word_name} ")
Sensit_data
.
word_name
=
qdata
.
query_params
[
'word_name'
]
return SuccessResponse(jsondatas, count=1)
return
SuccessResponse
(
await
crud
.
SensitiveDal
(
auth
.
db
)
.
create_data
(
data
=
Sensit_data
))
"""
@
router
.
get
(
"/get_sensitives"
,
summary
=
"获取敏感词列表"
)
@
router
.
get
(
"/get_sensitives"
,
summary
=
"获取敏感词列表"
)
async
def
get_sensitives
(
para
:
SensitiveParams
=
Depends
(),
auth
:
Auth
=
Depends
(
OpenAuth
())):
async
def
get_sensitives
(
para
:
SensitiveParams
=
Depends
(),
auth
:
Auth
=
Depends
(
OpenAuth
())):
...
@@ -179,7 +122,7 @@ async def delete_sensitives(data: Request, auth: Auth = Depends(OpenAuth())):
...
@@ -179,7 +122,7 @@ async def delete_sensitives(data: Request, auth: Auth = Depends(OpenAuth())):
print
(
'sensitive request is None'
)
print
(
'sensitive request is None'
)
return
ErrorResponse
(
"不能删除当前敏感词"
)
return
ErrorResponse
(
"不能删除当前敏感词"
)
else
:
else
:
print
(
f
"
req词条:{data.query_params['word_name
']} "
)
print
(
f
"
word_id:{data.query_params['word_id
']} "
)
data_id
=
data
.
query_params
[
'word_id'
]
data_id
=
data
.
query_params
[
'word_id'
]
sensitiveids
=
[
data_id
]
sensitiveids
=
[
data_id
]
...
...
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