-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_answer_relevancy.py
43 lines (29 loc) · 1.23 KB
/
test_answer_relevancy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from deepeval import assert_test
from deepeval.test_case import LLMTestCase
from deepeval.metrics import AnswerRelevancyMetric
from vertex_ai.google_vertex_ai import GoogleVertexAI
from vertex_ai.google_vertex_ai_langchain import GoogleVertexAILangChain
from utils import get_project_id
# The answer relevancy metric measures the quality of your RAG pipeline's generator by evaluating how relevant the
# actual_output of your LLM application is compared to the provided input
# https://docs.confident-ai.com/docs/metrics-answer-relevancy
TEST_MODEL = "gemini-2.0-flash-001"
EVAL_MODEL = "gemini-2.0-pro-exp-02-05"
LOCATION = "us-central1"
def test_answer_relevancy():
test_model = GoogleVertexAI(model_name=TEST_MODEL,
project=get_project_id(),
location=LOCATION)
input = "Why is sky blue?"
test_case = LLMTestCase(
input=input,
actual_output=test_model.generate(input)
)
eval_model = GoogleVertexAI(model_name=EVAL_MODEL,
project=get_project_id(),
location=LOCATION)
metric = AnswerRelevancyMetric(
model=eval_model,
threshold=0.5)
assert_test(test_case, [metric])