Skip to content

Commit dbf91ab

Browse files
committed
chore: remove deprecated functions (#2412)
1 parent 8824c4c commit dbf91ab

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
@@ -153,79 +153,6 @@ def init(self, run_config: RunConfig) -> None:
153153
"""
154154
...
155155

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

230157
@dataclass
231158
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)