mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-11 00:23:42 +08:00
feat: 初步兼容敏感词过滤
This commit is contained in:
32
constant/sensitive.go
Normal file
32
constant/sensitive.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package constant
|
||||
|
||||
import "strings"
|
||||
|
||||
var CheckSensitiveEnabled = true
|
||||
var CheckSensitiveOnPromptEnabled = true
|
||||
var CheckSensitiveOnCompletionEnabled = true
|
||||
|
||||
// StopOnSensitiveEnabled 如果检测到敏感词,是否立刻停止生成,否则替换敏感词
|
||||
var StopOnSensitiveEnabled = true
|
||||
|
||||
// SensitiveWords 敏感词
|
||||
// var SensitiveWords []string
|
||||
var SensitiveWords = []string{
|
||||
"test",
|
||||
}
|
||||
|
||||
func SensitiveWordsToString() string {
|
||||
return strings.Join(SensitiveWords, "\n")
|
||||
}
|
||||
|
||||
func SensitiveWordsFromString(s string) {
|
||||
SensitiveWords = strings.Split(s, "\n")
|
||||
}
|
||||
|
||||
func ShouldCheckPromptSensitive() bool {
|
||||
return CheckSensitiveEnabled && CheckSensitiveOnPromptEnabled
|
||||
}
|
||||
|
||||
func ShouldCheckCompletionSensitive() bool {
|
||||
return CheckSensitiveEnabled && CheckSensitiveOnCompletionEnabled
|
||||
}
|
||||
Reference in New Issue
Block a user