AI识别 增加标题检测

This commit is contained in:
chfei committed 2026-11-09 10:50:48 +08:00
1 parent be76e62ddd
commit 3f11ae23bd
2 files changed
+17 -1

No files matched your search

+8 -1
View File
@@ -37,7 +37,8 @@ public sealed class ComplianceResult
public string Error { get; internal set; }
public string Status => Error != null ? "失败,可重试" : Hits.Length == 0 ? "安全" : "有风险";
public string Summary => Error != null ? "失败:" + Error :
Hits.Length == 0 ? Status : $"有风险:第 {HitImageNumber} 张图片命中关键词:{string.Join(",", Hits)}";
Hits.Length == 0 ? Status : $"有风险:{HitSource}命中关键词:{string.Join(",", Hits)}";
private string HitSource => HitImageNumber == 0 ? "标题" : $"第 {HitImageNumber} 张图片";
}
public sealed class ComplianceBatchResult
@@ -217,6 +218,12 @@ public static class GoodsComplianceService
{
cancellationToken.ThrowIfCancellationRequested();
if (string.IsNullOrWhiteSpace(product?.ProductId)) throw new InvalidDataException("缺少商品 ID。");
result.Hits = Matches(product.Title ?? string.Empty, words);
if (result.Hits.Length > 0)
{
result.Text = product.Title;
return result;
}
var urls = SelectImages(product.MainImages, options.MainCount)
.Concat(SelectImages(product.DetailImages, options.DetailCount));
if (options.IncludeSku) urls = urls.Concat(SelectImages(product.Skus?.Select(s => s?.ImageUrl), null));
+9
View File
@@ -50,6 +50,15 @@ internal static class GoodsComplianceSmoke
Check(words.Length == 5);
Check(GoodsComplianceService.Matches("ABC广告", words).SequenceEqual(new[] { "广告", "abc" }));
Check(GoodsComplianceService.Matches("普通商品", words).Length == 0);
// Exercise detection without calling the reporting API.
var detect = typeof(GoodsComplianceService).GetMethod("DetectProductAsync",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
var titleHit = ((System.Threading.Tasks.Task<ComplianceResult>)detect.Invoke(null, new object[]
{
new Product { ProductId = "title", Title = "ABC广告" }, new ComplianceOptions(), words, null,
System.Threading.CancellationToken.None
})).GetAwaiter().GetResult();
Check(titleHit.Status == "有风险" && titleHit.Summary == "有风险:标题命中关键词:广告,abc");
var invalidImage = new Product { ProductId = "bad-image", MainImages = new List<string> { "file:///image.jpg" } };
var statuses = new List<string>();
GoodsComplianceService.DetectSelectedAsync(new[] { cloud }, item => invalidImage,