全网最全面的 DeepEval从入门到精通教程 - DeepEval 5分钟快速入门

发布时间:2026/7/26 2:29:40
全网最全面的 DeepEval从入门到精通教程 - DeepEval 5分钟快速入门 文章目录DeepEval 5分钟快速入门安装创建您的首次测试运行DeepEval 5分钟快速入门本快速入门指南将引导您在几分钟内完成从安装 DeepEval 到首次成功评估的整个过程。您将创建一个小型测试用例选择一个指标然后运行它deepeval test run。完成本快速入门指南后您应该能够使用测试用例、指标和deepeval test run.当您想要评估人工智能代理或其内部组件时请添加跟踪功能。了解数据集、合成数据、集成和 Confident AI 平台的下一步发展方向。安装在新建的虚拟环境中运行pip install -U deepevaldeepevalDeepEval会在本地环境中运行评估。要将测试报告集中存储在云端请使用 Confident AI 这是一个 AI 质量平台具备可观测性、评估和监控功能DeepEval 可与其原生集成deepeval login您的浏览器仅负责身份验证。登录或创建帐户后请返回终端输入您的姓名和组织确认预填的初始项目名称或选择您现有的项目之一。DeepEval 会自动创建并保存一个专用的项目 API 密钥。对于 CI 或其他非交互式环境请传递一个现有的密钥deepeval login --api-key ...。配置环境变量DeepEval 会自动加载环境文件在导入时优先级现有进程环境 -.env.local-.env选择退出设置DEEPEVAL_DISABLE_DOTENV1更多env设置信息请点击 此处查看。# quickstart cp .env.example .env.local # then edit .env.local (ignored by git)创建您的首次测试运行创建一个测试文件来运行你的第一个端到端评估。fromdeepevalimportassert_testfromdeepeval.modelsimportOllamaModelfromdeepeval.test_caseimportLLMTestCase,SingleTurnParamsfromdeepeval.metricsimportAnswerRelevancyMetric,GEval# 使用本地 Ollama 模型进行评估llm_modelOllamaModel(modelqwen3:0.6b)deftest_correctness():test_caseLLMTestCase(inputWhat is your return policy?,actual_outputYoure eligible for a free full refund within 30 days of purchase.,expected_outputYoure eligible for a free full refund within 30 days of purchase.,)answer_relevancy_metricAnswerRelevancyMetric(threshold0.5,modelllm_model,)correctness_metricGEval(nameCorrectness,criteriaDetermine if the actual output is correct based on the expected output.,evaluation_params[SingleTurnParams.ACTUAL_OUTPUT,SingleTurnParams.EXPECTED_OUTPUT,],modelllm_model,)assert_test(test_case,[answer_relevancy_metric,correctness_metric])执行结果(2 durations 0.005s hidden.Use-vv to show these durations.)1 passed,3 warnings in 12.37s Test Results ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Test case ┃ Metric ┃ Score ┃ Status ┃ Overall Success Rate ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩ │ test_correctness │ │ │ │ 100.0% │ │ │ Answer Relevancy │ 0.67(threshold0.5,evaluation modelqwen3:0.6b(Ollama),reasonThe score is 0.67 │ PASSED │ │ │ │ │ because there is one irrelevant statement in the actual output that does not address │ │ │ │ │ │ the input question aboutreturnpolicy.,errorNone)│ │ │ │ │ Correctness[GEval]│ 1.0(threshold0.5,evaluation modelqwen3:0.6b(Ollama),reasonThe output matches │ PASSED │ │ │ │ │ the expected output exactly in content and structure.No errors or inconsistencies │ │ │ │ │ │ were found,and there are no additional details present.The score is 10 as it │ │ │ │ │ │ reflects strong alignment with the evaluation steps.,errorNone)│ │ │ │ Note: Use Confident AI with DeepEval to analyze failed test casesformore details │ │ │ │ │ └────────────────────────────────────────────────────────────────────────────────────┴─────────────────────┴──────────────────────────────────────────────────────────────────────────────────────┴────────┴──────────────────────┘ ⚠ WARNING: No hyperparameters logged.» Log hyperparameters to attribute prompts and models to your test runs. ✓ Evaluation completed !(time taken: 12.58s|token cost: None)» Test Results(1 total tests): » Pass Rate: 100.0%|Passed: 1|Failed: 0 » Want to share evals with your team,or a placeforyour test cases to live? ❤️ » Rundeepeval viewto analyze and save testing results on Confident AI.恭喜您的测试用例应该已经通过✅ 让我们来分析一下发生了什么。input 模拟用户输入actual_output 是应用程序根据此输入应输出内容的占位符。expected_output 代表给定的理想答案inputGEval是由提供的研究支持的指标deepeval用于以类似人类的准确度评估 LLM 输出的任何自定义指标。在这个例子中指标是基于所提供的criteria数据的正确性但并非所有指标都需要数据。actual_outputexpected_outputexpected_output所有指标分数范围为 0 - 1阈threshold0.5值最终决定你的测试是否通过。