aliyun sensor server
This commit is contained in:
@@ -128,27 +128,52 @@ func QiniuTextCensorParser(raw []byte) (*TextCensorResponse, error) {
|
||||
var hint string
|
||||
var detailKey string
|
||||
var confidence float64
|
||||
for _, detail := range responseJSON.Result.Scenes.Antispam.Details {
|
||||
if detail.Label == "normal" {
|
||||
// 收集全部非 normal 维度的判定明细,供严格度策略按维度裁决(见 policy.go)。
|
||||
// 只取首个维度的做法会丢掉其余维度信息,无法做到「只拦高置信度的辱骂」。
|
||||
details := make([]LabelScore, 0, len(responseJSON.Result.Scenes.Antispam.Details))
|
||||
for _, d := range responseJSON.Result.Scenes.Antispam.Details {
|
||||
if d.Label == "normal" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get the first context as the hint, forbidden type, confidence.
|
||||
for _, context := range detail.Contexts {
|
||||
hint = context.Context
|
||||
details = append(details, LabelScore{
|
||||
Label: formatQiniuForbiddenType(d.Label),
|
||||
Score: d.Score,
|
||||
})
|
||||
|
||||
// 保留原有语义:首个非 normal 维度决定 ForbiddenType / Hint / Confidence。
|
||||
if detailKey == "" {
|
||||
for _, context := range d.Contexts {
|
||||
hint = context.Context
|
||||
}
|
||||
detailKey = d.Label
|
||||
confidence = d.Score
|
||||
}
|
||||
detailKey = detail.Label
|
||||
confidence = detail.Score
|
||||
break
|
||||
}
|
||||
|
||||
pass := responseJSON.IsPass()
|
||||
|
||||
// 整体建议优先取外层,缺失时回退到 antispam 场景的建议。
|
||||
suggestion := responseJSON.Result.Suggestion
|
||||
if suggestion == "" {
|
||||
suggestion = responseJSON.Result.Scenes.Antispam.Suggestion
|
||||
}
|
||||
// 建议字段整体缺失、但服务自身判定为不放行时,把整体建议补成 block:
|
||||
// 否则策略层会因「没有明细维度 + 没有建议」把它当成未命中而放行,
|
||||
// 与改造前的 fail-closed 行为不一致。
|
||||
if suggestion == "" && !pass {
|
||||
suggestion = SuggestionBlock
|
||||
}
|
||||
|
||||
return &TextCensorResponse{
|
||||
SourceName: "qiniu",
|
||||
Pass: responseJSON.IsPass(),
|
||||
ForbiddenType: formatQiniuForbiddenType(detailKey),
|
||||
Hint: hint,
|
||||
Confidence: confidence,
|
||||
RawResponse: raw,
|
||||
SourceName: "qiniu",
|
||||
Pass: pass,
|
||||
ForbiddenType: formatQiniuForbiddenType(detailKey),
|
||||
Hint: hint,
|
||||
Confidence: confidence,
|
||||
RawResponse: raw,
|
||||
Details: details,
|
||||
ProviderSuggestion: suggestion,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user