Commit 08e22821 authored by 于飞's avatar 于飞

聊天敏感词拦截

parent 22d623f5
......@@ -43,6 +43,9 @@ from dbgpt.util.executor_utils import (
blocking_func_to_async,
)
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()
......@@ -344,6 +347,7 @@ async def chat_prepare(dialogue: ConversationVo = Body()):
async def chat_completions(
dialogue: ConversationVo = Body(),
flow_service: FlowService = Depends(get_chat_flow),
auth: Auth = Depends(OpenAuth()),
):
logger.info(
f"chat_completions:{dialogue.chat_mode},{dialogue.select_param},{dialogue.model_name}"
......@@ -354,6 +358,24 @@ async def chat_completions(
"Connection": "keep-alive",
"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)
if dialogue.chat_mode == ChatScene.ChatAgent.value():
return StreamingResponse(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment