refactor: Introduce accumulate_usage function for token aggregation, enhance alias map expansion in BatchProcessor, and streamline error handling in PreclassificationService. Update PDF processing utilities for improved image conversion and error logging.

This commit is contained in:
erik
2026-03-01 20:55:52 -05:00
parent 3c258ebf12
commit e7fde25227
29 changed files with 321 additions and 1206 deletions
+10
View File
@@ -81,6 +81,16 @@ def compute_cost_from_usage(
}
def accumulate_usage(agg: Dict[str, Any], new_usage: Dict[str, Any] | None) -> None:
"""Acumula tokens de `new_usage` en el dict agregado `agg` (in-place)."""
if not isinstance(new_usage, dict):
return
agg["prompt_tokens"] += int(new_usage.get("prompt_tokens") or 0)
agg["completion_tokens"] += int(new_usage.get("completion_tokens") or 0)
details = new_usage.get("prompt_tokens_details") or {}
agg["prompt_tokens_details"]["cached_tokens"] += int(details.get("cached_tokens") or 0)
def sum_costs(a: Dict[str, Any] | None, b: Dict[str, Any] | None) -> Dict[str, Any]:
"""Suma dos objetos de costos."""
def safe(x): return float(x) if x is not None else 0.0