fromdeepevalimportassert_testfromdeepeval.metricsimportAnswerRelevancyMetric,FaithfulnessMetricfromdeepeval.test_caseimportLLMTestCasedeftest_rag():case=LLMTestCase(input="What is the capital of France?",actual_output="Paris is the capital of France.",retrieval_context=["France's capital city is Paris."],)assert_test(case,[AnswerRelevancyMetric(threshold=0.8),FaithfulnessMetric(threshold=0.8),])
importpytestfromcheckllmimportllm_check@llm_check(metrics=["answer_relevance","hallucination"],threshold=0.8)deftest_rag():return{"input":"What is the capital of France?","output":"Paris is the capital of France.","context":["France's capital city is Paris."],}
fromdatasetsimportDatasetfromragasimportevaluatefromragas.metricsimportfaithfulness,answer_relevancydataset=Dataset.from_dict({"question":["What is the capital of France?"],"answer":["Paris is the capital of France."],"contexts":[["France's capital city is Paris."]],"ground_truth":["Paris"],})result=evaluate(dataset,metrics=[faithfulness,answer_relevancy])print(result)
importpytest@pytest.mark.parametrize("case",[{"input":"What is the capital of France?","output":"Paris is the capital of France.","context":["France's capital city is Paris."],"expected":"Paris",}])deftest_rag(case,llm_judge):llm_judge(input=case["input"],output=case["output"],context=case["context"],expected_output=case["expected"],metrics=["hallucination","answer_relevance"],threshold=0.8,)