Skip to content

Commit

Permalink
update test case col names in grade_answer.py
Browse files Browse the repository at this point in the history
Signed-off-by: minmin-intel <[email protected]>
  • Loading branch information
minmin-intel committed Sep 9, 2024
1 parent e4cd9c6 commit 69f87c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,24 @@


def convert_data_format_for_ragas(data):
# data: pandas dataframe
# columns: ['query', 'answer', 'ref_answer']
# return: a dict with keys: 'input', 'actual_output', 'expected_output'
output = {
"input": data["query"].tolist(),
"actual_output": data["answer"].tolist(),
"expected_output": data["ref_answer"].tolist(),
"retrieval_context": [["dummy_context"] for _ in range(data["query"].shape[0])],
"question": data["query"].tolist(),
"answer": data["answer"].tolist(),
"ground_truth": data["ref_answer"].tolist(),
"contexts": [["dummy_context"] for _ in range(data["query"].shape[0])],
}
return output


def make_list_of_test_cases(data):
# data: pandas dataframe
# columns: ['query', 'answer', 'ref_answer']
# return: a list of dicts with keys: 'input', 'actual_output', 'expected_output'
output = []
for _, row in data.iterrows():
output.append(
{
"input": [row["query"]],
"actual_output": [row["answer"]],
"expected_output": [row["ref_answer"]],
"retrieval_context": [["dummy_context"]],
"question": [row["query"]],
"answer": [row["answer"]],
"ground_truth": [row["ref_answer"]],
"contexts": [["dummy_context"]],
}
)
return output
Expand Down
9 changes: 5 additions & 4 deletions tests/test_ragas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@


import unittest

import os
from evals.metrics.ragas import RagasMetric


host_ip = os.getenv("host_ip", "localhost")
port = os.getenv("port", "8008")
class TestRagasMetric(unittest.TestCase):

@unittest.skip("need pass localhost id")
# @unittest.skip("need pass localhost id")
def test_ragas(self):
# Replace this with the actual output from your LLM application
actual_output = "We offer a 30-day full refund at no extra cost."
Expand All @@ -24,7 +25,7 @@ def test_ragas(self):
from langchain_community.embeddings import HuggingFaceBgeEmbeddings

embeddings = HuggingFaceBgeEmbeddings(model_name="BAAI/bge-base-en-v1.5")
metric = RagasMetric(threshold=0.5, model="http://localhost:8008", embeddings=embeddings)
metric = RagasMetric(threshold=0.5, model=f"http://{host_ip}:{port}", embeddings=embeddings)
test_case = {
"question": ["What if these shoes don't fit?"],
"answer": [actual_output],
Expand Down

0 comments on commit 69f87c2

Please sign in to comment.