Files
wehub-resource-sync e768098d0e
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:52 +08:00

38 lines
1.0 KiB
Python

from promptflow.core import tool
from typing import List
@tool
def match(answer: List[str], ground_truth: List[str]):
exact_match = 0
partial_match = 0
if is_match(answer, ground_truth, ignore_case=True, ignore_order=True, allow_partial=False):
exact_match = 1
if is_match(answer, ground_truth, ignore_case=True, ignore_order=True, allow_partial=True):
partial_match = 1
return {"exact_match": exact_match, "partial_match": partial_match, "answer": answer, "ground_truth": ground_truth}
def is_match(
answer: List[str],
ground_truth: List[str],
ignore_case: bool,
ignore_order: bool,
allow_partial: bool) -> bool:
if ignore_case:
answer = [a.lower() for a in answer]
ground_truth = [g.lower() for g in ground_truth]
if ignore_order:
answer.sort()
ground_truth.sort()
if allow_partial:
x = [a for a in answer if a in ground_truth]
return x == answer
return answer == ground_truth