update for ragas
This commit is contained in:
@@ -29,10 +29,15 @@ def _format_log_summary(diagnoses: list[Diagnosis], advice_path: Path) -> str:
|
||||
|
||||
|
||||
def _build_fallback_report(diagnoses: list[Diagnosis]) -> str:
|
||||
"""Build a rules-only report when LLM analysis is unavailable."""
|
||||
"""Build a rules-only report when LLM analysis is unavailable.
|
||||
|
||||
Even without the LLM, embed each metric's worst sample(s) — question,
|
||||
answer, ground truth — so the advice still references concrete problems
|
||||
instead of reading as a purely generic template.
|
||||
"""
|
||||
if not diagnoses:
|
||||
return ""
|
||||
lines = ["## 规则诊断(LLM 分析不可用)\n"]
|
||||
lines = ["## 规则诊断(LLM 分析不可用,以下为规则引擎输出)\n"]
|
||||
for d in diagnoses:
|
||||
label = _SEVERITY_LABEL.get(d.severity, d.severity)
|
||||
lines.append(f"### {d.metric} [{label}] 均值={d.mean_score:.4f}")
|
||||
@@ -42,6 +47,22 @@ def _build_fallback_report(diagnoses: list[Diagnosis]) -> str:
|
||||
lines.append("\n**建议动作:**")
|
||||
for action in d.suggested_actions:
|
||||
lines.append(f"- {action}")
|
||||
if d.low_samples:
|
||||
lines.append("\n**低分样本举例拆解:**")
|
||||
for i, sample in enumerate(d.low_samples, 1):
|
||||
score = sample.get(d.metric, "N/A")
|
||||
question = str(sample.get("question", "")).strip() or "(无问题文本)"
|
||||
lines.append(f"\n- **样本 {i}**({d.metric}={score})问题:{question}")
|
||||
answer = str(sample.get("answer", "")).strip()
|
||||
if answer:
|
||||
lines.append(f" - 生成答案:{answer[:200]}")
|
||||
ground_truth = str(sample.get("ground_truth", "")).strip()
|
||||
if ground_truth:
|
||||
lines.append(f" - 标准答案:{ground_truth[:160]}")
|
||||
lines.append(
|
||||
f" - 拆解:该样本 {d.metric} 偏低,请对照上述「可能原因 / 建议动作」"
|
||||
f"重点排查本问题的检索片段与生成答案。"
|
||||
)
|
||||
lines.append("")
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user