Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
eda2ac43
authored
Mar 20, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 敏感词库为空时,不检测
parent
38305d77
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletions
+13
-1
constant/sensitive.go
+7
-1
service/sensitive.go
+6
-0
No files found.
constant/sensitive.go
View file @
eda2ac43
...
@@ -23,7 +23,13 @@ func SensitiveWordsToString() string {
...
@@ -23,7 +23,13 @@ func SensitiveWordsToString() string {
}
}
func
SensitiveWordsFromString
(
s
string
)
{
func
SensitiveWordsFromString
(
s
string
)
{
SensitiveWords
=
strings
.
Split
(
s
,
"
\n
"
)
sw
:=
strings
.
Split
(
s
,
"
\n
"
)
for
_
,
w
:=
range
sw
{
w
=
strings
.
TrimSpace
(
w
)
if
w
!=
""
{
SensitiveWords
=
append
(
SensitiveWords
,
w
)
}
}
}
}
func
ShouldCheckPromptSensitive
()
bool
{
func
ShouldCheckPromptSensitive
()
bool
{
...
...
service/sensitive.go
View file @
eda2ac43
...
@@ -10,6 +10,9 @@ import (
...
@@ -10,6 +10,9 @@ import (
// SensitiveWordContains 是否包含敏感词,返回是否包含敏感词和敏感词列表
// SensitiveWordContains 是否包含敏感词,返回是否包含敏感词和敏感词列表
func
SensitiveWordContains
(
text
string
)
(
bool
,
[]
string
)
{
func
SensitiveWordContains
(
text
string
)
(
bool
,
[]
string
)
{
if
len
(
constant
.
SensitiveWords
)
==
0
{
return
false
,
nil
}
checkText
:=
strings
.
ToLower
(
text
)
checkText
:=
strings
.
ToLower
(
text
)
// 构建一个AC自动机
// 构建一个AC自动机
m
:=
initAc
()
m
:=
initAc
()
...
@@ -26,6 +29,9 @@ func SensitiveWordContains(text string) (bool, []string) {
...
@@ -26,6 +29,9 @@ func SensitiveWordContains(text string) (bool, []string) {
// SensitiveWordReplace 敏感词替换,返回是否包含敏感词和替换后的文本
// SensitiveWordReplace 敏感词替换,返回是否包含敏感词和替换后的文本
func
SensitiveWordReplace
(
text
string
,
returnImmediately
bool
)
(
bool
,
[]
string
,
string
)
{
func
SensitiveWordReplace
(
text
string
,
returnImmediately
bool
)
(
bool
,
[]
string
,
string
)
{
if
len
(
constant
.
SensitiveWords
)
==
0
{
return
false
,
nil
,
text
}
checkText
:=
strings
.
ToLower
(
text
)
checkText
:=
strings
.
ToLower
(
text
)
m
:=
initAc
()
m
:=
initAc
()
hits
:=
m
.
MultiPatternSearch
([]
rune
(
checkText
),
returnImmediately
)
hits
:=
m
.
MultiPatternSearch
([]
rune
(
checkText
),
returnImmediately
)
...
...
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