十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

DeepEval 社区自定义指标有哪些以及怎么加入自己的评估流程

DeepEval 社区自定义指标有哪些以及怎么加入自己的评估流程 DeepEval 社区自定义指标有哪些以及怎么加入自己的评估流程【免费下载链接】deepevalThe LLM Evaluation Framework项目地址: https://gitcode.com/GitHub_Trending/de/deepeval如果你在 DeepEvaldeepeval的内置指标里找不到覆盖你评估需求的那一项可以看看它的community社区贡献指标由用户贡献、面向特定评估场景的扩展指标官方明确说明community标签不代表质量差或不支持只表示指标仍处于 beta 阶段API、打分行为和文档仍可能引入 breaking change。截至当前仓库文档社区指标共有三个且都不能从deepeval.metrics直接导入必须显式从deepeval.metrics.community导入指标用途是否需要 LLM评估对象CitationFaithfulnessMetric检查 RAG 输出中每个[N]引用标记是否指向真正支持该论断的检索段落需要LLM-as-a-judge单轮文本用例AgentLoopDetectionMetric检测 agent 是否陷入死循环或循环执行模式不需要完全确定性计算agent 执行 traceToolPermissionMetric按 allowlist/denylist 检查 agent 是否只调用了被授权的工具不需要确定性计算用例的tools_called源码入口可以在 deepeval/metrics/community/init.py 看到目前该包显式导出了CitationFaithfulnessMetricAgentLoopDetectionMetric与ToolPermissionMetric的文档同样要求从deepeval.metrics.community导入。本文以当前文档描述的导入方式为准。把社区指标接入已有的 evaluate() 流程DeepEval 的标准评估入口是evaluate(test_cases[...], metrics[...])。社区指标的接入方式与内置指标一致构造指标对象放入metrics参数即可。以下示例来自 Citation Faithfulness 文档/metrics-citation-faithfulness.mdx)它演示了把CitationFaithfulnessMetric加入端到端评估的完整写法from deepeval import evaluate from deepeval.test_case import LLMTestCase from deepeval.metrics.community import CitationFaithfulnessMetric # Replace this with the actual output from your LLM application. # The completion-year claim is cited to passage [1], which only covers height. actual_output The Eiffel Tower was completed in 1889 [1]. # Replace this with the actual retrieved context from your RAG pipeline retrieval_context [ The Eiffel Tower stands 330 metres tall in Paris., The Eiffel Tower was completed in 1889 for the World Fair., ] metric CitationFaithfulnessMetric() test_case LLMTestCase( inputHow tall is the Eiffel Tower and when was it completed?, actual_outputactual_output, retrieval_contextretrieval_context, ) evaluate(test_cases[test_case], metrics[metric])这段代码中你需要替换的是两处业务数据actual_output你的 LLM 应用真实输出其中用[N]标记引用和retrieval_contextRAG 管线检索到的段落列表。指标会把段落按[1]、[2]... 编号后交给 judge 比对。文档说明retrieval_context必须配合input、actual_output一起出现在LLMTestCase中。上面的示例输出了一个故意写错的引用完成年份的论断被引到了只讲高度的段落[1]。按文档说明FaithfulnessMetric会放过这条回答因为年份确实被段落[2]支持而CitationFaithfulnessMetric会判失败——这正是引入该指标的原因它能捕获引错段落的归属错误。CitationFaithfulnessMetric 的常用参数文档列出 8 个可选参数与任务最相关的是threshold最低通过分数默认1.0。分数是二值的——faithful 为1.0unfaithful 为0.0所以默认要求完全忠实才通过。设为None可进入 score-only 模式。model指定 OpenAI 的 GPT 模型名或任意DeepEvalBaseLLM类型的自定义模型。strict_modeTrue时强制二值打分并覆盖threshold为 1。async_mode/verbose_mode/include_reason/flaky控制并发、控制台中间步骤打印、是否附理由、以及把该指标标记为 flaky。在 agent 评估中加入确定性指标另外两个社区指标都不需要 LLM适合放在 CI 里做零 token 成本的检查。它们的接入路径分别是evals_iteratortrace 类和evaluate()用例类。AgentLoopDetectionMetric需要先开 tracingAgentLoopDetectionMetric是trace-only指标读取update_current_trace设置的 agent trace因此前提是已按 DeepEval 的 tracing 文档完成observe接入用例只需input和actual_output两个标准字段。文档给出的用法是配合EvaluationDataset的evals_iteratorfrom deepeval.tracing import observe, update_current_trace from deepeval.dataset import Golden, EvaluationDataset from deepeval.metrics.community import AgentLoopDetectionMetric observe() def search_web(query: str) - str: # Your tool implementation return fResults for: {query} observe() def my_agent(input: str) - str: result search_web(input) update_current_trace(inputinput, outputresult) return result # Create dataset dataset EvaluationDataset(goldens[Golden(inputWhat is the weather in Paris?)]) # Initialize metric — no model or API key needed loop_metric AgentLoopDetectionMetric(threshold0.5) # Evaluate for golden in dataset.evals_iterator(metrics[loop_metric]): my_agent(golden.input)这里search_web和my_agent是你的业务代码需要替换成自己的实现update_current_trace(input..., output...)用来向 trace 写入输入输出。该指标不支持model参数三个子信号工具重复调用、推理停滞、调用图环全部用哈希、集合运算、序列比较等确定性算法计算相同 trace 必然得到相同分数。关键可选参数threshold默认0.5分数范围0.0严重循环到1.0干净执行。repetition_threshold默认3同名同参工具调用重复多少次后标记为重复。similarity_threshold默认0.85相邻 LLM 输出相似度超过该值即视为停滞。check_tool_repetition/check_reasoning_stagnation/check_call_graph_cycles三个子信号可独立开关关闭后其权重会从分母中剔除不会拉低总分。strict_mode、verbose_mode、flaky行为与内置指标一致。文档还给出了两种可选的替代运行方式在嵌套组件上用observe(metrics[loop_metric])做组件级评估或作为 standalone 直接metric.measure(test_case)。standalone 方式文档明确提醒拿不到测试报告、Confident AI 平台集成以及evaluate()/deepeval test run提供的速度、缓存等优化只适合调试或自建管线。ToolPermissionMetric给 agent 上权限白名单ToolPermissionMetric校验 agent 是否只调用了被授权的工具与ToolCorrectnessMetric对比实际调用 vs 预期调用不同它做的是授权检查任何超出 allowlist 或落在 denylist 上的调用都算越权不管任务是否完成。用例只需提供tools_called文档示例from deepeval import evaluate from deepeval.metrics.community import ToolPermissionMetric from deepeval.test_case import LLMTestCase, ToolCall metric ToolPermissionMetric( allowed_tools[search_kb, reply_to_customer], # allowlist (least privilege) denied_tools[issue_refund], # optional denylist threshold1.0, verbose_modeTrue, ) test_case LLMTestCase( inputWhat is my refund status?, actual_outputYour refund is being processed., tools_called[ToolCall(namesearch_kb)], ) evaluate(test_cases[test_case], metrics[metric])allowed_tools与denied_tools至少提供一个denylist 的优先级永远高于 allowlist。allowed_tools/denied_tools要替换成你自己 agent 的工具名。分数是授权调用数 / 总调用数未调用任何工具时得分为1。它同样支持 standalone 运行metric.measure(test_case)后读metric.score和metric.reason。如何确认结果score、reason 与示例输出三个指标都是自解释指标measure()或evaluate()运行后通过metric.score和metric.reason读取判定结果。AgentLoopDetectionMetric还提供metric.score_breakdown按子信号单独暴露得分tool_repetition、reasoning_stagnation、call_graph_cycles。下面是文档给出的示例输出仅作格式参考不是每次运行的固定值Agent Loop Detection Score: 0.25 Reason: Tool search_web called 6 times with identical arguments. Identical reasoning outputs at steps 2 and 3.文档同时给出了分数解读表1.0表示无循环模式0.5–1.0表示轻度问题有重复或重叠agent 大概率能恢复0.0–0.5表示严重循环建议人工复核0.0表示出现完全相同的重复调用或真正的调用图环。CitationFaithfulnessMetric的判定同样是二值结论——faithful 记1.0所有论断有支持且每个[N]都指向支持它的段落unfaithful 记0.0存在无支持论断、与段落矛盾、或引用指向了不支持该论断的段落。使用社区指标的边界beta 状态社区指标可能收到 breaking changeAPI、打分行为和文档都会随成熟度调整升级deepeval版本后如有异常优先检查这几个指标的接口。导入方式固定不要写成from deepeval.metrics import ...文档明确要求显式从deepeval.metrics.community导入。前置依赖AgentLoopDetectionMetric必须先完成 tracing 接入observeupdate_current_trace否则 trace 为空、无从分析CitationFaithfulnessMetric必须有retrieval_context且输出中的引用是[N]形式ToolPermissionMetric必须能拿到真实的tools_called。走向核心指标的路径文档说明社区指标若要晋升为核心指标需要匹配的文档与示例、覆盖通过/失败/边界行为的测试、符合现有约定的稳定 API以及广泛有用的证据。在此之前应把它们当作迭代更快的贡献扩展来对待。三个指标的完整文档分别在 Citation Faithfulness/metrics-citation-faithfulness.mdx)、Agent Loop Detection/metrics-agent-loop-detection.mdx)、Tool Permission/metrics-tool-permission.mdx)实现代码可对照 deepeval/metrics/community/、deepeval/metrics/agent_loop_detection/、deepeval/metrics/tool_permission/。【免费下载链接】deepevalThe LLM Evaluation Framework项目地址: https://gitcode.com/GitHub_Trending/de/deepeval创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表