Skip to content

Commit 9f22937

Browse files
authored
fix: load response as json (#341)
1 parent 4138abc commit 9f22937

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/ragas/metrics/_context_recall.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import re
43
import typing as t
54
from dataclasses import dataclass
65

@@ -10,6 +9,7 @@
109
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
1110

1211
from ragas.metrics.base import EvaluationMode, MetricWithLLM
12+
from ragas.utils import load_as_json
1313

1414
CONTEXT_RECALL_RA = HumanMessagePromptTemplate.from_template(
1515
"""
@@ -114,10 +114,8 @@ def _score_batch(
114114
responses = [[i.text for i in r] for r in results.generations]
115115
scores = []
116116
for response in responses:
117-
pattern = "\[\s*\{.*?\}(\s*,\s*\{.*?\})*\s*\]"
118-
match = re.search(pattern, response[0].replace("\n", ""))
119-
if match:
120-
response = eval(response[0])
117+
response = load_as_json(response[0])
118+
if response:
121119
denom = len(response)
122120
numerator = sum(
123121
item.get("Attributed").lower() == "yes" for item in response

0 commit comments

Comments
 (0)