mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 20:57:32 +08:00
fix(ai-security-guard): compatible with old configs (#2941)
This commit is contained in:
@@ -81,11 +81,11 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Data struct {
|
type Data struct {
|
||||||
RiskLevel string `json:"RiskLevel"`
|
RiskLevel string `json:"RiskLevel"`
|
||||||
AttackLevel string `json:"AttackLevel,omitempty"`
|
AttackLevel string `json:"AttackLevel,omitempty"`
|
||||||
Result []Result `json:"Result,omitempty"`
|
Result []Result `json:"Result,omitempty"`
|
||||||
Advice []Advice `json:"Advice,omitempty"`
|
Advice []Advice `json:"Advice,omitempty"`
|
||||||
Detail []Detail `json:"Detail,omitempty"`
|
Detail []Detail `json:"Detail,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
@@ -123,6 +123,7 @@ type AISecurityConfig struct {
|
|||||||
denyCode int64
|
denyCode int64
|
||||||
denyMessage string
|
denyMessage string
|
||||||
protocolOriginal bool
|
protocolOriginal bool
|
||||||
|
riskLevelBar string
|
||||||
contentModerationLevelBar string
|
contentModerationLevelBar string
|
||||||
promptAttackLevelBar string
|
promptAttackLevelBar string
|
||||||
sensitiveDataLevelBar string
|
sensitiveDataLevelBar string
|
||||||
@@ -224,7 +225,7 @@ func isRiskLevelAcceptable(action string, data Data, config AISecurityConfig) bo
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return levelToInt(data.RiskLevel) < levelToInt(config.contentModerationLevelBar)
|
return levelToInt(data.RiskLevel) < levelToInt(config.riskLevelBar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,8 +282,17 @@ func parseConfig(json gjson.Result, config *AISecurityConfig) error {
|
|||||||
if config.ak == "" || config.sk == "" {
|
if config.ak == "" || config.sk == "" {
|
||||||
return errors.New("invalid AK/SK config")
|
return errors.New("invalid AK/SK config")
|
||||||
}
|
}
|
||||||
|
if obj := json.Get("riskLevelBar"); obj.Exists() {
|
||||||
|
config.riskLevelBar = obj.String()
|
||||||
|
} else {
|
||||||
|
config.riskLevelBar = HighRisk
|
||||||
|
}
|
||||||
config.token = json.Get("securityToken").String()
|
config.token = json.Get("securityToken").String()
|
||||||
config.action = json.Get("action").String()
|
if obj := json.Get("action"); obj.Exists() {
|
||||||
|
config.action = json.Get("action").String()
|
||||||
|
} else {
|
||||||
|
config.action = "TextModerationPlus"
|
||||||
|
}
|
||||||
config.checkRequest = json.Get("checkRequest").Bool()
|
config.checkRequest = json.Get("checkRequest").Bool()
|
||||||
config.checkResponse = json.Get("checkResponse").Bool()
|
config.checkResponse = json.Get("checkResponse").Bool()
|
||||||
config.protocolOriginal = json.Get("protocol").String() == "original"
|
config.protocolOriginal = json.Get("protocol").String() == "original"
|
||||||
|
|||||||
Reference in New Issue
Block a user