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
08e22821
Commit
08e22821
authored
Sep 05, 2024
by
于飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
聊天敏感词拦截
parent
22d623f5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
api_v1.py
dbgpt/app/openapi/api_v1/api_v1.py
+22
-0
No files found.
dbgpt/app/openapi/api_v1/api_v1.py
View file @
08e22821
...
@@ -43,6 +43,9 @@ from dbgpt.util.executor_utils import (
...
@@ -43,6 +43,9 @@ from dbgpt.util.executor_utils import (
blocking_func_to_async
,
blocking_func_to_async
,
)
)
from
dbgpt.util.tracer
import
SpanType
,
root_tracer
from
dbgpt.util.tracer
import
SpanType
,
root_tracer
from
dbgpt.app.apps.utils.filter
import
mydfafiter
from
dbgpt.app.apps.vadmin.auth.utils.current
import
AllUserAuth
,
FullAdminAuth
,
OpenAuth
from
dbgpt.app.apps.vadmin.auth.utils.validation.auth
import
Auth
router
=
APIRouter
()
router
=
APIRouter
()
...
@@ -344,6 +347,7 @@ async def chat_prepare(dialogue: ConversationVo = Body()):
...
@@ -344,6 +347,7 @@ async def chat_prepare(dialogue: ConversationVo = Body()):
async
def
chat_completions
(
async
def
chat_completions
(
dialogue
:
ConversationVo
=
Body
(),
dialogue
:
ConversationVo
=
Body
(),
flow_service
:
FlowService
=
Depends
(
get_chat_flow
),
flow_service
:
FlowService
=
Depends
(
get_chat_flow
),
auth
:
Auth
=
Depends
(
OpenAuth
()),
):
):
logger
.
info
(
logger
.
info
(
f
"chat_completions:{dialogue.chat_mode},{dialogue.select_param},{dialogue.model_name}"
f
"chat_completions:{dialogue.chat_mode},{dialogue.select_param},{dialogue.model_name}"
...
@@ -354,6 +358,24 @@ async def chat_completions(
...
@@ -354,6 +358,24 @@ async def chat_completions(
"Connection"
:
"keep-alive"
,
"Connection"
:
"keep-alive"
,
"Transfer-Encoding"
:
"chunked"
,
"Transfer-Encoding"
:
"chunked"
,
}
}
# 从数据库中加载 并且初始化敏感词-->到内存中
await
mydfafiter
.
parse_from_db
(
auth
.
db
)
# 先判断敏感词
dfa_result
,
is_sensitive
=
mydfafiter
.
filter
(
dialogue
.
user_input
,
"*"
)
print
(
dfa_result
)
if
is_sensitive
:
print
(
'用户输入有敏感词'
)
result
=
{
'code'
:
200
,
'message'
:
'success'
,
'data'
:
[{
'type'
:
3
,
'word_name'
:
'111'
,
'is_sensitive'
:
1
,
'user_input'
:
dfa_result
}]}
return
StreamingResponse
(
'error:1001'
,
headers
=
headers
,
media_type
=
"text/event-stream"
,
)
domain_type
=
_parse_domain_type
(
dialogue
)
domain_type
=
_parse_domain_type
(
dialogue
)
if
dialogue
.
chat_mode
==
ChatScene
.
ChatAgent
.
value
():
if
dialogue
.
chat_mode
==
ChatScene
.
ChatAgent
.
value
():
return
StreamingResponse
(
return
StreamingResponse
(
...
...
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