Commit c88a4da9 by CaIon

fix: fix error

parent be2c13fb
...@@ -56,7 +56,7 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*d ...@@ -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) { ...@@ -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
......
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 sign in to comment