Skip to content

Commit 4cb829d

Browse files
authored
chore: remove deprecated functions (#2412)
1 parent b99907c commit 4cb829d

File tree

5 files changed

+21
-125
lines changed

5 files changed

+21
-125
lines changed

src/ragas/metrics/_answer_correctness.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
257257
else:
258258
assert self.answer_similarity is not None, "AnswerSimilarity must be set"
259259

260-
similarity_score = await self.answer_similarity.ascore(
261-
row, callbacks=callbacks
260+
similarity_score = await self.answer_similarity.single_turn_ascore(
261+
SingleTurnSample(**row), callbacks=callbacks
262262
)
263263

264264
score = np.average(

src/ragas/metrics/_context_precision.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
)
1919
from ragas.prompt import PydanticPrompt
2020
from ragas.run_config import RunConfig
21-
from ragas.utils import deprecated
2221

2322
if t.TYPE_CHECKING:
2423
from langchain_core.callbacks import Callbacks
@@ -317,12 +316,6 @@ async def _single_turn_ascore(
317316
) -> float:
318317
return await super()._single_turn_ascore(sample, callbacks)
319318

320-
@deprecated(
321-
since="0.2", removal="0.3", alternative="LLMContextPrecisionWithReference"
322-
)
323-
async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
324-
return await super()._ascore(row, callbacks)
325-
326319

327320
@dataclass
328321
class ContextUtilization(LLMContextPrecisionWithoutReference):
@@ -333,12 +326,6 @@ async def _single_turn_ascore(
333326
) -> float:
334327
return await super()._single_turn_ascore(sample, callbacks)
335328

336-
@deprecated(
337-
since="0.2", removal="0.3", alternative="LLMContextPrecisionWithoutReference"
338-
)
339-
async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
340-
return await super()._ascore(row, callbacks)
341-
342329

343330
context_precision = ContextPrecision()
344331
context_utilization = ContextUtilization()

src/ragas/metrics/_context_recall.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
)
1919
from ragas.prompt import PydanticPrompt
2020
from ragas.run_config import RunConfig
21-
from ragas.utils import deprecated
2221

2322
if t.TYPE_CHECKING:
2423
from langchain_core.callbacks import Callbacks
@@ -161,17 +160,6 @@ async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
161160
class ContextRecall(LLMContextRecall):
162161
name: str = "context_recall"
163162

164-
@deprecated(since="0.2", removal="0.3", alternative="LLMContextRecall")
165-
async def _single_turn_ascore(
166-
self, sample: SingleTurnSample, callbacks: Callbacks
167-
) -> float:
168-
row = sample.to_dict()
169-
return await self._ascore(row, callbacks)
170-
171-
@deprecated(since="0.2", removal="0.3", alternative="LLMContextRecall")
172-
async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
173-
return await super()._ascore(row, callbacks)
174-
175163

176164
@dataclass
177165
class NonLLMContextRecall(SingleTurnMetric):

src/ragas/metrics/base.py

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ragas.metrics.validators import AllowedValuesType
2121
from ragas.prompt import FewShotPydanticPrompt, PromptMixin
2222
from ragas.run_config import RunConfig
23-
from ragas.utils import camel_to_snake, deprecated, get_metric_language
23+
from ragas.utils import camel_to_snake, get_metric_language
2424

2525
if t.TYPE_CHECKING:
2626
from langchain_core.callbacks import Callbacks
@@ -150,79 +150,6 @@ def init(self, run_config: RunConfig) -> None:
150150
"""
151151
...
152152

153-
@deprecated("0.2", removal="0.3", alternative="single_turn_ascore")
154-
def score(self, row: t.Dict, callbacks: Callbacks = None) -> float:
155-
"""
156-
Calculates the score for a single row of data.
157-
158-
Note
159-
----
160-
This method is deprecated and will be removed in 0.3. Please use `single_turn_ascore` or `multi_turn_ascore` instead.
161-
"""
162-
callbacks = callbacks or []
163-
rm, group_cm = new_group(
164-
self.name,
165-
inputs=row,
166-
callbacks=callbacks,
167-
metadata={"type": ChainType.METRIC},
168-
)
169-
170-
async def _async_wrapper():
171-
try:
172-
result = await self._ascore(row=row, callbacks=group_cm)
173-
except Exception as e:
174-
if not group_cm.ended:
175-
rm.on_chain_error(e)
176-
raise e
177-
else:
178-
if not group_cm.ended:
179-
rm.on_chain_end({"output": result})
180-
return result
181-
182-
# Apply nest_asyncio logic to ensure compatibility in notebook/Jupyter environments.
183-
apply_nest_asyncio()
184-
return run(_async_wrapper)
185-
186-
@deprecated("0.2", removal="0.3", alternative="single_turn_ascore")
187-
async def ascore(
188-
self,
189-
row: t.Dict,
190-
callbacks: Callbacks = None,
191-
timeout: t.Optional[float] = None,
192-
) -> float:
193-
"""
194-
Asynchronously calculates the score for a single row of data.
195-
196-
Note
197-
----
198-
This method is deprecated and will be removed in 0.3. Please use `single_turn_ascore` instead.
199-
"""
200-
callbacks = callbacks or []
201-
rm, group_cm = new_group(
202-
self.name,
203-
inputs=row,
204-
callbacks=callbacks,
205-
metadata={"type": ChainType.METRIC},
206-
)
207-
try:
208-
score = await asyncio.wait_for(
209-
self._ascore(row=row, callbacks=group_cm),
210-
timeout=timeout,
211-
)
212-
except Exception as e:
213-
if not group_cm.ended:
214-
rm.on_chain_error(e)
215-
raise e
216-
else:
217-
if not group_cm.ended:
218-
rm.on_chain_end({"output": score})
219-
return score
220-
221-
async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
222-
raise NotImplementedError(
223-
f"Metric '{self.name}' has no implementation for _ascore. score() is deprecated and will be removed in 0.3. Please use single_turn_ascore or multi_turn_ascore instead."
224-
)
225-
226153

227154
@dataclass
228155
class MetricWithLLM(Metric, PromptMixin):

tests/unit/test_executor_in_jupyter.ipynb

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,7 @@
5656
"execution_count": null,
5757
"metadata": {},
5858
"outputs": [],
59-
"source": [
60-
"async def _run():\n",
61-
" results = []\n",
62-
" for t in as_completed([echo(1), echo(2), echo(3)], 3):\n",
63-
" r = await t\n",
64-
" results.append(r)\n",
65-
" return results\n",
66-
"\n",
67-
"\n",
68-
"results = await _run()\n",
69-
"\n",
70-
"expected = [1, 2, 3]\n",
71-
"assert results == expected, f\"got: {results}, expected: {expected}\""
72-
]
59+
"source": "async def _run():\n results = []\n for task in as_completed([echo(1), echo(2), echo(3)], 3):\n r = await task\n results.append(r)\n return results\n\n\nresults = await _run()\n\nexpected = [1, 2, 3]\nassert results == expected, f\"got: {results}, expected: {expected}\""
7360
},
7461
{
7562
"cell_type": "markdown",
@@ -215,18 +202,25 @@
215202
"metadata": {},
216203
"outputs": [],
217204
"source": [
218-
"from ragas.metrics.base import Metric\n",
205+
"import typing as t\n",
206+
"from dataclasses import dataclass, field\n",
207+
"\n",
208+
"from ragas.dataset_schema import SingleTurnSample\n",
209+
"from ragas.metrics.base import MetricType, SingleTurnMetric\n",
219210
"\n",
220211
"\n",
221-
"class FakeMetric(Metric):\n",
222-
" name = \"fake_metric\"\n",
223-
" _required_columns = (\"user_input\", \"response\")\n",
212+
"@dataclass\n",
213+
"class FakeMetric(SingleTurnMetric):\n",
214+
" name: str = \"fake_metric\"\n",
215+
" _required_columns: t.Dict[MetricType, t.Set[str]] = field(\n",
216+
" default_factory=lambda: {MetricType.SINGLE_TURN: {\"user_input\", \"response\"}}\n",
217+
" )\n",
224218
"\n",
225-
" def init(self):\n",
219+
" def init(self, run_config=None):\n",
226220
" pass\n",
227221
"\n",
228-
" async def _ascore(self, row, callbacks) -> float:\n",
229-
" return 0\n",
222+
" async def _single_turn_ascore(self, sample: SingleTurnSample, callbacks) -> float:\n",
223+
" return 0.0\n",
230224
"\n",
231225
"\n",
232226
"fm = FakeMetric()"
@@ -238,8 +232,8 @@
238232
"metadata": {},
239233
"outputs": [],
240234
"source": [
241-
"score = fm.score({\"user_input\": \"a\", \"response\": \"b\"})\n",
242-
"assert score == 0"
235+
"score = await fm.single_turn_ascore(SingleTurnSample(user_input=\"a\", response=\"b\"))\n",
236+
"assert score == 0.0"
243237
]
244238
},
245239
{
@@ -326,4 +320,4 @@
326320
},
327321
"nbformat": 4,
328322
"nbformat_minor": 2
329-
}
323+
}

0 commit comments

Comments
 (0)