文章目录
- 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_DOTENV=1
更多env设置信息请点击 此处查看。
# quickstart cp .env.example .env.local # then edit .env.local (ignored by git)创建您的首次测试运行
创建一个测试文件来运行你的第一个端到端评估。
fromdeepevalimportassert_testfromdeepeval.modelsimportOllamaModelfromdeepeval.test_caseimportLLMTestCase,SingleTurnParamsfromdeepeval.metricsimportAnswerRelevancyMetric,GEval# 使用本地 Ollama 模型进行评估llm_model=OllamaModel(model="qwen3:0.6b")deftest_correctness():test_case=LLMTestCase(input="What is your return policy?",actual_output="You're eligible for a free full refund within 30 days of purchase.",expected_output="You're eligible for a free full refund within 30 days of purchase.",)answer_relevancy_metric=AnswerRelevancyMetric(threshold=0.5,model=llm_model,)correctness_metric=GEval(name="Correctness",criteria="Determine if the actual output is correct based on the expected output.",evaluation_params=[SingleTurnParams.ACTUAL_OUTPUT,SingleTurnParams.EXPECTED_OUTPUT,],model=llm_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(threshold=0.5,evaluation model=qwen3:0.6b(Ollama),reason=The score is 0.67 │ PASSED │ │ │ │ │ because there is one irrelevant statement in the actual output that does not address │ │ │ │ │ │ the input question aboutreturnpolicy.,error=None)│ │ │ │ │ Correctness[GEval]│ 1.0(threshold=0.5,evaluation model=qwen3:0.6b(Ollama),reason=The 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.,error=None)│ │ │ │ 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? ❤️ 🏡 » Run'deepeval view'to analyze and save testing results on Confident AI.恭喜!您的测试用例应该已经通过✅ 让我们来分析一下发生了什么。
- input 模拟用户输入
- actual_output 是应用程序根据此输入应输出内容的占位符。
- expected_output 代表给定的理想答案input,
- GEval是由提供的研究支持的指标,
deepeval用于以类似人类的准确度评估 LLM 输出的任何自定义指标。
在这个例子中,指标是基于所提供的criteria数据的正确性,但并非所有指标都需要数据。actual_outputexpected_outputexpected_output
所有指标分数范围为 0 - 1,阈threshold=0.5值最终决定你的测试是否通过。