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
234a6ad2
Commit
234a6ad2
authored
Sep 14, 2024
by
于飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
在编辑,添加,删除的时候,更新关键词
parent
a59352e2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
7 deletions
+61
-7
filter.py
dbgpt/app/apps/utils/filter.py
+26
-0
keywordsviews.py
dbgpt/app/apps/vadmin/keywordsviews.py
+11
-4
views.py
dbgpt/app/apps/vadmin/media/views.py
+24
-3
No files found.
dbgpt/app/apps/utils/filter.py
View file @
234a6ad2
...
@@ -49,6 +49,32 @@ class DFAFilter():
...
@@ -49,6 +49,32 @@ class DFAFilter():
if
i
==
len
(
chars
)
-
1
:
if
i
==
len
(
chars
)
-
1
:
level
[
self
.
delimit
]
=
0
level
[
self
.
delimit
]
=
0
#从字典中删除一个关键词
def
remove
(
self
,
keyword
):
"""Remove a keyword from the DFA filter"""
if
not
isinstance
(
keyword
,
str
):
keyword
=
keyword
.
decode
(
'utf-8'
)
keyword
=
keyword
.
lower
()
chars
=
keyword
.
strip
()
if
not
chars
:
return
def
_remove_recursively
(
level
,
chars
,
index
):
"""Helper function to recursively remove the keyword."""
if
index
==
len
(
chars
):
if
self
.
delimit
in
level
:
# Remove the terminal node (end of the keyword)
del
level
[
self
.
delimit
]
return
len
(
level
)
==
0
char
=
chars
[
index
]
if
char
in
level
and
_remove_recursively
(
level
[
char
],
chars
,
index
+
1
):
# If the sub-level is empty, remove this character
del
level
[
char
]
return
len
(
level
)
==
0
return
False
_remove_recursively
(
self
.
keyword_chains
,
chars
,
0
)
#从文本里加载 敏感词
#从文本里加载 敏感词
def
parse
(
self
,
path
):
def
parse
(
self
,
path
):
with
open
(
path
,
encoding
=
'UTF-8'
)
as
f
:
with
open
(
path
,
encoding
=
'UTF-8'
)
as
f
:
...
...
dbgpt/app/apps/vadmin/keywordsviews.py
View file @
234a6ad2
...
@@ -170,12 +170,19 @@ async def get_spacy_keywords(dialogue: ConversationVo = Body(), auth: Auth = Dep
...
@@ -170,12 +170,19 @@ async def get_spacy_keywords(dialogue: ConversationVo = Body(), auth: Auth = Dep
return
SuccessResponse
(
result
)
#返回type=3
return
SuccessResponse
(
result
)
#返回type=3
#没有敏感词的时候,查找是否有相关图片 或者 视频
#没有敏感词的时候,查找是否有相关图片 或者 视频
#words = get_key_words(dialogue.user_input)
words
=
get_key_words_nlp
(
dialogue
.
user_input
)
#100%匹配算法 | 只取匹配到的第一个
words
=
get_key_words_nlp
(
dialogue
.
user_input
)
#100%匹配算法 | 只取匹配到的第一个
if
len
(
words
)
>
0
:
if
len
(
words
)
>
0
:
print
(
f
"----匹配到的关键词--->:{words[0]}"
)
print
(
f
"---
算法1
-匹配到的关键词--->:{words[0]}"
)
result
=
await
get_media_datas
(
dialogue
.
conv_uid
,
words
[
0
],
auth
.
db
)
result
=
await
get_media_datas
(
dialogue
.
conv_uid
,
words
[
0
],
auth
.
db
)
return
SuccessResponse
(
result
)
return
SuccessResponse
(
result
)
else
:
print
(
f
"---算法2-begin--->"
)
#上面的算法没找到,换一种算法继续找
words2
=
get_key_words
(
dialogue
.
user_input
)
if
len
(
words2
)
>
0
:
print
(
f
"---算法2-匹配到的关键词--->:{words[0]}"
)
result
=
await
get_media_datas
(
dialogue
.
conv_uid
,
words2
[
0
],
auth
.
db
)
return
SuccessResponse
(
result
)
else
:
else
:
print
(
f
"-----没有找到需要查询的内容:---->"
)
print
(
f
"-----没有找到需要查询的内容:---->"
)
return
ErrorResponse
(
"没有找到需要查询的内容"
)
return
ErrorResponse
(
"没有找到需要查询的内容"
)
...
...
dbgpt/app/apps/vadmin/media/views.py
View file @
234a6ad2
...
@@ -9,6 +9,7 @@ from . import schemas, crud
...
@@ -9,6 +9,7 @@ from . import schemas, crud
from
.params.media_list
import
MediaListParams
,
GroupListParams
,
MediaEditParams
,
QuestionListParams
,
\
from
.params.media_list
import
MediaListParams
,
GroupListParams
,
MediaEditParams
,
QuestionListParams
,
\
QuestionEditParams
,
CorrelationListParams
QuestionEditParams
,
CorrelationListParams
from
...core.dependencies
import
IdList
from
...core.dependencies
import
IdList
from
dbgpt.app.apps.utils.filter
import
mydfafiter
,
mydfafiter_picture
,
mydfafiter_question
,
mydfafiter_video
router
=
APIRouter
()
router
=
APIRouter
()
...
@@ -67,7 +68,11 @@ async def media_edit(params: MediaEditParams = Depends(), auth: Auth = Depends(F
...
@@ -67,7 +68,11 @@ async def media_edit(params: MediaEditParams = Depends(), auth: Auth = Depends(F
@
router
.
post
(
"/question/add"
,
summary
=
"新建问答对"
)
@
router
.
post
(
"/question/add"
,
summary
=
"新建问答对"
)
async
def
question_add
(
data
:
schemas
.
Question
,
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
question_add
(
data
:
schemas
.
Question
,
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
crud
.
QuestionDal
(
auth
.
db
)
.
create_data
(
data
=
data
))
ret
=
await
crud
.
QuestionDal
(
auth
.
db
)
.
create_data
(
data
=
data
)
if
len
(
ret
)
>
0
:
print
(
f
"-------------------------add->:{ret}"
)
mydfafiter_question
.
add
(
data
.
key_word
)
# 向关键词字典中添加一个新的问答对
return
SuccessResponse
(
ret
)
@
router
.
get
(
"/question/list"
,
summary
=
"问答对列表"
)
@
router
.
get
(
"/question/list"
,
summary
=
"问答对列表"
)
...
@@ -78,12 +83,28 @@ async def question_list(params: QuestionListParams = Depends(), auth: Auth = Dep
...
@@ -78,12 +83,28 @@ async def question_list(params: QuestionListParams = Depends(), auth: Auth = Dep
@
router
.
post
(
"/question/del"
,
summary
=
"删除问答对"
)
@
router
.
post
(
"/question/del"
,
summary
=
"删除问答对"
)
async
def
question_add
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
question_add
(
ids
:
IdList
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
crud
.
QuestionDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
True
))
ret
=
await
crud
.
QuestionDal
(
auth
.
db
)
.
delete_datas
(
ids
.
ids
,
v_soft
=
True
)
#print(f"-------------------------delete->:{ret}")
question_dic
=
{
'page'
:
1
,
'limit'
:
0
,
'v_order'
:
None
,
'v_order_field'
:
None
,
'id'
:
ids
.
ids
[
0
]}
question_datas
,
count
=
await
crud
.
QuestionDal
(
auth
.
db
)
.
get_datas
(
**
question_dic
,
v_return_count
=
True
)
if
len
(
question_datas
)
>
0
:
print
(
f
"------要删除问答对------>:{question_datas[0]}"
)
mydfafiter_question
.
remove
(
question_datas
[
0
]
.
get
(
'key_word'
))
# 将关键词字典中删除一个新的问答对
return
SuccessResponse
(
ret
)
@
router
.
post
(
"/question/edit"
,
summary
=
"编辑问答对"
)
@
router
.
post
(
"/question/edit"
,
summary
=
"编辑问答对"
)
async
def
question_edit
(
params
:
QuestionEditParams
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
async
def
question_edit
(
params
:
QuestionEditParams
=
Depends
(),
auth
:
Auth
=
Depends
(
FullAdminAuth
())):
return
SuccessResponse
(
await
crud
.
QuestionDal
(
auth
.
db
)
.
update_question_datas
(
params
))
if
len
(
params
.
key_word
)
>
0
:
question_dic
=
{
'page'
:
1
,
'limit'
:
0
,
'v_order'
:
None
,
'v_order_field'
:
None
,
'id'
:
params
.
ids
[
0
]}
question_datas
,
count
=
await
crud
.
QuestionDal
(
auth
.
db
)
.
get_datas
(
**
question_dic
,
v_return_count
=
True
)
if
len
(
question_datas
)
>
0
:
print
(
f
"------编辑时要删除旧的问答对------>:{question_datas[0]}"
)
mydfafiter_question
.
remove
(
question_datas
[
0
]
.
get
(
'key_word'
))
print
(
f
"------编辑时要添加新的问答对------>:{params.key_word}"
)
mydfafiter_question
.
add
(
params
.
key_word
)
ret
=
await
crud
.
QuestionDal
(
auth
.
db
)
.
update_question_datas
(
params
)
return
SuccessResponse
(
ret
)
...
...
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