Skip to content

Commit

Permalink
fixes ToolCallAccuracy raises ZeroDivisionError when called without a…
Browse files Browse the repository at this point in the history
…ny arguments
  • Loading branch information
sahusiddharth committed Nov 17, 2024
1 parent 44f09b8 commit 2e504f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/ragas/metrics/_answer_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

from ragas.dataset_schema import SingleTurnSample
from ragas.embeddings.base import HuggingfaceEmbeddings
from ragas.metrics.base import (
MetricType,
MetricWithEmbeddings,
SingleTurnMetric,
)
from ragas.metrics.base import MetricType, MetricWithEmbeddings, SingleTurnMetric

if t.TYPE_CHECKING:
from langchain_core.callbacks.base import Callbacks
Expand Down
6 changes: 3 additions & 3 deletions src/ragas/metrics/_aspect_critic.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class AspectCriticWithReference(AspectCritic):
)

async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:

if self.llm is None:
raise ValueError("LLM is not set")

Expand Down Expand Up @@ -320,10 +320,10 @@ async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
async def _multi_turn_ascore(
self, sample: MultiTurnSample, callbacks: Callbacks
) -> float:

if self.llm is None:
raise ValueError("LLM is not set")

if sample.reference is None:
raise ValueError("Reference is not set")

Expand Down
5 changes: 1 addition & 4 deletions src/ragas/metrics/_noise_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ async def _decompose_answer_into_statements(
assert self.sentence_segmenter is not None, "sentence_segmenter is not set"

sentences = self.sentence_segmenter.segment(text)
sentences_with_index = {
i: sentence
for i, sentence in enumerate(sentences)
}
sentences_with_index = {i: sentence for i, sentence in enumerate(sentences)}

statements_simplified = await self.statement_prompt.generate(
llm=self.llm,
Expand Down
5 changes: 5 additions & 0 deletions src/ragas/metrics/_tool_call_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def init(self, run_config):
async def _get_arg_score(
self, preds: t.Dict[str, t.Any], refs: t.Dict[str, t.Any], callbacks: Callbacks
) -> float:
if not refs and not preds:
return 1.0
if not refs:
return 0.0

score = 0.0
for arg in refs.keys():
if arg in preds:
Expand Down
10 changes: 8 additions & 2 deletions src/ragas/testset/transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from .base import BaseGraphTransformation, Extractor, RelationshipBuilder, Splitter, NodeFilter
from .base import (
BaseGraphTransformation,
Extractor,
NodeFilter,
RelationshipBuilder,
Splitter,
)
from .default import default_transforms
from .engine import Parallel, Transforms, apply_transforms, rollback_transforms
from .extractors import (
Expand All @@ -8,12 +14,12 @@
SummaryExtractor,
TitleExtractor,
)
from .filters import CustomNodeFilter
from .relationship_builders.cosine import (
CosineSimilarityBuilder,
SummaryCosineSimilarityBuilder,
)
from .splitters import HeadlineSplitter
from .filters import CustomNodeFilter

__all__ = [
# base
Expand Down
1 change: 1 addition & 0 deletions src/ragas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def num_tokens_from_string(string: str, encoding_name: str = "cl100k_base") -> i
num_tokens = len(encoding.encode(string))
return num_tokens


def batched(iterable: t.Iterable, n: int) -> t.Iterator[t.Tuple]:
"""Batch data from the iterable into tuples of length n. The last batch may be shorter than n."""
# batched('ABCDEFG', 3) → ABC DEF G
Expand Down

0 comments on commit 2e504f5

Please sign in to comment.