Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
LLM-Filter
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
2026_NGIT
LLM-Filter
Commits
7a1720ea
Commit
7a1720ea
authored
Dec 08, 2025
by
uuo00_n
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(conversation): 更新敏感词处理逻辑以兼容新旧版本
处理敏感词时添加对新版结构化数据的支持,同时保持对旧版字符串列表的兼容 修改数据库连接配置为本地开发环境
parent
adff7ae9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
15 deletions
+21
-15
.env
.env
+2
-1
conversation.cpython-39.pyc
app/services/__pycache__/conversation.cpython-39.pyc
+0
-0
conversation.py
app/services/conversation.py
+19
-14
No files found.
.env
View file @
7a1720ea
# 数据库配置
# 注意:生产环境请通过安全的环境变量管理传递凭据,避免将敏感信息提交到版本库
MONGODB_URL=mongodb://llm:fSjFMwyShmcH4GdR@datacenter.dldzxx.cn:27017/llm?authSource=llm
# MONGODB_URL=mongodb://llm:fSjFMwyShmcH4GdR@datacenter.dldzxx.cn:27017/llm?authSource=llm
MONGODB_URL=mongodb://localhost:27017/
DB_NAME=llm
# JWT配置
...
...
app/services/__pycache__/conversation.cpython-39.pyc
View file @
7a1720ea
No preview for this file type
app/services/conversation.py
View file @
7a1720ea
...
...
@@ -114,19 +114,24 @@ async def add_message(conversation_id: str, user_id: str, content: str) -> Dict[
# 详细敏感词信息(用于响应与审计)
detailed_words
:
List
[
Dict
[
str
,
Any
]]
=
[]
if
contains_sensitive
and
sensitive_words
:
cursor
=
db
.
db
.
sensitive_words
.
find
({
"word"
:
{
"$in"
:
sensitive_words
}})
async
for
doc
in
cursor
:
detailed_words
.
append
({
"word"
:
doc
.
get
(
"word"
),
"category"
:
doc
.
get
(
"category"
),
"subcategory"
:
doc
.
get
(
"subcategory"
),
"severity"
:
doc
.
get
(
"severity"
,
1
),
})
# 对未命中库的词提供兜底
known
=
set
(
dw
[
"word"
]
for
dw
in
detailed_words
)
for
w
in
sensitive_words
:
if
w
not
in
known
:
detailed_words
.
append
({
"word"
:
w
,
"category"
:
None
,
"subcategory"
:
None
,
"severity"
:
1
})
# 新版过滤器已返回结构化信息,直接使用;兼容旧版字符串列表
if
isinstance
(
sensitive_words
[
0
],
dict
):
detailed_words
=
sensitive_words
else
:
words_list
=
[
w
for
w
in
sensitive_words
if
isinstance
(
w
,
str
)]
if
words_list
:
cursor
=
db
.
db
.
sensitive_words
.
find
({
"word"
:
{
"$in"
:
words_list
}})
async
for
doc
in
cursor
:
detailed_words
.
append
({
"word"
:
doc
.
get
(
"word"
),
"category"
:
doc
.
get
(
"category"
),
"subcategory"
:
doc
.
get
(
"subcategory"
),
"severity"
:
doc
.
get
(
"severity"
,
1
),
})
known
=
set
(
dw
[
"word"
]
for
dw
in
detailed_words
)
for
w
in
words_list
:
if
w
not
in
known
:
detailed_words
.
append
({
"word"
:
w
,
"category"
:
None
,
"subcategory"
:
None
,
"severity"
:
1
})
# 创建用户消息(消息中也保存结构化敏感词列表,便于后续展示)
user_message
=
{
...
...
@@ -297,4 +302,4 @@ async def delete_conversation(conversation_id: str, user_id: str) -> bool:
"conversation_id"
:
ObjectId
(
conversation_id
),
"user_id"
:
ObjectId
(
user_id
)
})
return
True
\ No newline at end of file
return
True
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