Skip to content

Commit

Permalink
chore (backend): leave aggregation of NoneType as is
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed Nov 26, 2024
1 parent f70121c commit cf3fd61
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions agenta-backend/agenta_backend/services/aggregation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def aggregate_float(results: List[Result]) -> Result:
"""

try:
average_value = sum(result.value or 0.0 for result in results) / len(results)
average_value = sum(result.value for result in results) / len(results)
return Result(type="number", value=average_value)
except Exception as exc:
return Result(
Expand All @@ -90,7 +90,7 @@ def aggregate_float_from_llm_app_response(
raise ValueError("Key is required to aggregate InvokationResult objects.")

values = [
getattr(inv_result, key) or 0.0
getattr(inv_result, key)
for inv_result in invocation_results
if hasattr(inv_result, key) and getattr(inv_result, key) is not None
]
Expand All @@ -116,17 +116,15 @@ def sum_float_from_llm_app_response(
raise ValueError("Key is required to aggregate InvokationResult objects.")

values = [
getattr(inv_result, key) or 0.0
getattr(inv_result, key)
for inv_result in invocation_results
if hasattr(inv_result, key) and getattr(inv_result, key) is not None
]

if not values:
raise ValueError(f"No valid values found for {key} sum aggregation.")

total_value = sum(
values
) # sum([3.453, None]) -> TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
total_value = sum(values)

return Result(type=key, value=total_value)
except Exception as exc:
Expand Down

0 comments on commit cf3fd61

Please sign in to comment.