fix(aihr): fail closed when formal finance evidence is missing
This commit is contained in:
+3
-1
@@ -388,9 +388,11 @@ public class AihrKnowledgeQueryService {
|
||||
List<Citation> citations = citations(
|
||||
app.tenantId(), spaceIds, legacy.snippets(), formalPolicyOnly, request.queryText());
|
||||
boolean noEvidence = citations.isEmpty();
|
||||
boolean formalPolicyRequest = formalPolicyOnly
|
||||
|| (execution.queryPlan() != null && !execution.queryPlan().requiredAuthorities().isEmpty());
|
||||
boolean needsClarification = execution.queryPlan() != null
|
||||
&& execution.queryPlan().needsClarification() && !citations.isEmpty();
|
||||
String answer = formalPolicyOnly && noEvidence
|
||||
String answer = formalPolicyRequest && noEvidence
|
||||
? "当前已批准且在有效期内的正式资料中没有找到足够依据,不能使用访谈、经验材料或草稿补全政策答案。"
|
||||
+ "请补充经审核的正式来源后再查询。"
|
||||
: legacy.answer();
|
||||
|
||||
+7
-7
@@ -3526,6 +3526,11 @@ public class AihrSopSeedService {
|
||||
for (int index = 0; index < ranked.size(); index++) ranked.get(index).candidateRank = index + 1;
|
||||
|
||||
List<CandidateAccumulator> evidence = ranked.stream().limit(RETRIEVAL_EVIDENCE_K).toList();
|
||||
if (requiresFormal && evidence.isEmpty()) {
|
||||
return new SearchExecution(noEvidenceResponse(queryText, category,
|
||||
List.of("没有找到当前有效且经过人工审核的正式制度、操作手册或已批准 SOP。")),
|
||||
plan, candidateTraces(candidates));
|
||||
}
|
||||
if (plan.needsClarification()) {
|
||||
markSupportingEvidence(evidence);
|
||||
String message = "已找到正式的费用报销资料,但当前问题中的金额口径不明确:请确认“"
|
||||
@@ -3533,11 +3538,6 @@ public class AihrSopSeedService {
|
||||
return new SearchExecution(clarificationResponse(queryText, category, message, evidence), plan,
|
||||
candidateTraces(candidates));
|
||||
}
|
||||
if (requiresFormal && evidence.isEmpty()) {
|
||||
return new SearchExecution(noEvidenceResponse(queryText, category,
|
||||
List.of("没有找到当前有效且经过人工审核的正式制度、操作手册或已批准 SOP。")),
|
||||
plan, candidateTraces(candidates));
|
||||
}
|
||||
if (requiresAmountEvidence(plan) && !supportsAmountRule(plan, evidence)) {
|
||||
markSupportingEvidence(evidence);
|
||||
String message = "已找到正式的费用报销操作资料,但当前正式资料没有证明“" + amountText(plan)
|
||||
@@ -3786,8 +3786,8 @@ public class AihrSopSeedService {
|
||||
List<KnowledgeHit> hits = supportingEvidence == null ? List.of()
|
||||
: supportingEvidence.stream().map(candidate -> candidate.hit).toList();
|
||||
if (hits.isEmpty()) {
|
||||
return new SearchResponse(queryText, firstNonBlank(category, "sop"), message, "正式证据不足,未生成流程",
|
||||
List.of(), List.of(), List.of(), records(), List.of(), List.of(message), null, null);
|
||||
return noEvidenceResponse(queryText, category,
|
||||
List.of("正式证据不足,未生成流程。", "请补充当前有效且经过人工审核的正式来源。"));
|
||||
}
|
||||
SearchResponse grounded = responseFromHits(category, queryText, hits, List.of(), RETRIEVAL_DISPLAY_K);
|
||||
String answer = message + (grounded.keyPoints().isEmpty() ? "" : "已确认的办理步骤见下方。");
|
||||
|
||||
+17
@@ -44,6 +44,23 @@ public class AihrSopSeedServiceTest {
|
||||
assertFalse(AihrSopSeedService.isNoEvidenceAnswer("已找到正式制度依据"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
public void formalNoEvidenceCannotUseTheFormalClarificationMessage() throws Exception {
|
||||
Path source = Path.of("src/main/java/org/dromara/aihr/service/AihrSopSeedService.java");
|
||||
if (!Files.exists(source)) {
|
||||
source = Path.of("ruoyi-modules/ruoyi-aihr/src/main/java/org/dromara/aihr/service/AihrSopSeedService.java");
|
||||
}
|
||||
String code = Files.readString(source).replace("\r\n", "\n");
|
||||
int noEvidenceBranch = code.indexOf("if (requiresFormal && evidence.isEmpty())");
|
||||
int clarificationBranch = code.indexOf("if (plan.needsClarification())");
|
||||
|
||||
assertTrue(noEvidenceBranch >= 0);
|
||||
assertTrue(clarificationBranch >= 0);
|
||||
assertTrue(noEvidenceBranch < clarificationBranch);
|
||||
assertTrue(code.contains("正式证据不足,未生成流程。"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
public void rawHitResponseKeepsSnippetsWhenDigestUnavailable() {
|
||||
|
||||
Reference in New Issue
Block a user