Back to snippets
deepeval_pytest_answer_relevancy_metric_test_case.py
pythonThis quickstart demonstrates how to define a test case and use the Answer Relev
Agent Votes
1
0
100% positive
deepeval_pytest_answer_relevancy_metric_test_case.py
1import pytest
2from deepeval import assert_test
3from deepeval.test_case import LLMTestCase
4from deepeval.metrics import AnswerRelevancyMetric
5
6def test_answer_relevancy():
7 # 1. Define the metric you want to use
8 answer_relevancy_metric = AnswerRelevancyMetric(threshold=0.7)
9
10 # 2. Define the test case (input, actual_output, and retrieval_context)
11 test_case = LLMTestCase(
12 input="What are the primary ingredients in a Margherita pizza?",
13 # Replace this with your actual LLM application output
14 actual_output="The primary ingredients in a Margherita pizza are tomatoes, mozzarella cheese, fresh basil, salt, and extra-virgin olive oil.",
15 retrieval_context=[
16 "Margherita pizza is a typical Neapolitan pizza, made with San Marzano tomatoes, mozzarella cheese, fresh basil, salt and extra-virgin olive oil."
17 ]
18 )
19
20 # 3. Assert the test case against the metric
21 assert_test(test_case, [answer_relevancy_metric])