MCPcopy Create free account
hub / github.com/google/adk-samples / compare_financials

Function compare_financials

python/agents/invoice-processing/eval/eval.py:209–251  ·  view source on GitHub ↗

Compare financial amounts (total, pretax, tax).

(gt: dict, agent: dict, tolerance: float)

Source from the content-addressed store, hash-verified

207
208
209def compare_financials(gt: dict, agent: dict, tolerance: float) -> dict:
210 """Compare financial amounts (total, pretax, tax)."""
211 gt_details = gt.get("Invoice Details") or {}
212 agent_details = agent.get("Invoice Details") or {}
213
214 fields = {
215 "Invoice Total": ("Invoice Total", tolerance),
216 "Pretax Total": ("Pretax Total", tolerance),
217 "Tax Amount": ("Tax Amount", tolerance),
218 }
219
220 results = {}
221 all_match = True
222
223 for label, (field_name, tol) in fields.items():
224 gt_val = gt_details.get(field_name, "")
225 agent_val = agent_details.get(field_name, "")
226 match = amounts_match(gt_val, agent_val, tol)
227 if not match:
228 all_match = False
229
230 results[label] = {
231 "ground_truth": gt_val,
232 "agent": agent_val,
233 "match": match,
234 }
235
236 # Currency
237 gt_currency = gt_details.get("Currency", "")
238 agent_currency = agent_details.get("Currency", "")
239 currency_match = normalize_string(gt_currency) == normalize_string(
240 agent_currency
241 )
242 results["Currency"] = {
243 "ground_truth": gt_currency,
244 "agent": agent_currency,
245 "match": currency_match,
246 }
247 if not currency_match:
248 all_match = False
249
250 results["all_match"] = all_match
251 return results
252
253
254def compare_vendor(gt: dict, agent: dict) -> dict:

Callers 1

_evaluate_legacyFunction · 0.85

Calls 4

amounts_matchFunction · 0.85
normalize_stringFunction · 0.85
itemsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected