mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-20 17:26:38 +08:00
fix: fix error
This commit is contained in:
parent
2db4282666
commit
47b9f48544
@ -56,7 +56,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*d
|
|||||||
sensitive := false
|
sensitive := false
|
||||||
if checkSensitive {
|
if checkSensitive {
|
||||||
// check sensitive
|
// check sensitive
|
||||||
sensitive, _, data = service.SensitiveWordReplace(data, constant.StopOnSensitiveEnabled)
|
sensitive, _, data = service.SensitiveWordReplace(data, false)
|
||||||
}
|
}
|
||||||
dataChan <- data
|
dataChan <- data
|
||||||
data = data[6:]
|
data = data[6:]
|
||||||
|
@ -25,15 +25,15 @@ 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) {
|
||||||
text = strings.ToLower(text)
|
checkText := strings.ToLower(text)
|
||||||
m := initAc()
|
m := initAc()
|
||||||
hits := m.MultiPatternSearch([]rune(text), returnImmediately)
|
hits := m.MultiPatternSearch([]rune(checkText), returnImmediately)
|
||||||
if len(hits) > 0 {
|
if len(hits) > 0 {
|
||||||
words := make([]string, 0)
|
words := make([]string, 0)
|
||||||
for _, hit := range hits {
|
for _, hit := range hits {
|
||||||
pos := hit.Pos
|
pos := hit.Pos
|
||||||
word := string(hit.Word)
|
word := string(hit.Word)
|
||||||
text = text[:pos] + " *###* " + text[pos+len(word):]
|
text = text[:pos] + "*###*" + text[pos+len(word):]
|
||||||
words = append(words, word)
|
words = append(words, word)
|
||||||
}
|
}
|
||||||
return true, words, text
|
return true, words, text
|
||||||
|
Loading…
Reference in New Issue
Block a user