From e080ea92ddf0f419162626f21dd7056bd5639118 Mon Sep 17 00:00:00 2001 From: Siddharth Sahu <112792547+sahusiddharth@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:55:31 +0530 Subject: [PATCH] Fixes ToolCallAccuracy raises ZeroDivisionError when called without any arguments. (#1685) - Fixes: #1684 1. Check for both empty dictionaries: - If both refs and preds are empty, return 1.0 as you specified in your logic. 2. Check for empty refs: - If refs is empty but preds is not, return 0.0 since there's nothing to compare. Co-authored-by: ikka --- src/ragas/metrics/_tool_call_accuracy.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ragas/metrics/_tool_call_accuracy.py b/src/ragas/metrics/_tool_call_accuracy.py index b89a23b49..8f29c81be 100644 --- a/src/ragas/metrics/_tool_call_accuracy.py +++ b/src/ragas/metrics/_tool_call_accuracy.py @@ -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: