feat(ai-security-guard): add Embedding API content detection support (#3895)

Signed-off-by: root <jianwei.wjw@alibaba-inc.com>
This commit is contained in:
JianweiWang
2026-06-02 12:11:00 +08:00
committed by GitHub
parent a45b1dde6c
commit 58ffdae6ba
5 changed files with 818 additions and 2 deletions

View File

@@ -118,6 +118,7 @@ const (
ApiTextGeneration = "text_generation"
ApiImageGeneration = "image_generation"
ApiMCP = "mcp"
ApiEmbedding = "embedding"
)
// provider types
@@ -206,6 +207,7 @@ type AISecurityConfig struct {
ResponseStreamContentJsonPath string
ResponseContentFallbackJsonPaths []string
ResponseStreamContentFallbackJsonPaths []string
ResponseErrorContentJsonPath string
DenyCode int64
DenyMessage string
ProtocolOriginal bool
@@ -223,7 +225,7 @@ type AISecurityConfig struct {
ConsumerRequestCheckService []map[string]interface{}
ConsumerResponseCheckService []map[string]interface{}
ConsumerRiskLevel []map[string]interface{}
// text_generation, image_generation, etc.
// text_generation, image_generation, embedding, etc.
ApiType string
// openai, qwen, comfyui, etc.
ProviderType string
@@ -355,6 +357,9 @@ func (config *AISecurityConfig) Parse(json gjson.Result) error {
} else if exists {
config.ResponseStreamContentFallbackJsonPaths = paths
}
if obj := json.Get("responseErrorContentJsonPath"); obj.Exists() {
config.ResponseErrorContentJsonPath = obj.String()
}
if obj := json.Get("contentModerationLevelBar"); obj.Exists() {
config.ContentModerationLevelBar = obj.String()
if LevelToInt(config.ContentModerationLevelBar) <= 0 {