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

28 lines
1.4 KiB
Python

from promptflow.core import tool
@tool
def validate_input(question: str, answer: str, context: str, ground_truth: str, selected_metrics: dict) -> dict:
input_data = {"question": question, "answer": answer, "context": context, "ground_truth": ground_truth}
expected_input_cols = set(input_data.keys())
dict_metric_required_fields = {"gpt_groundedness": set(["answer", "context"]),
"gpt_relevance": set(["question", "answer", "context"]),
"gpt_coherence": set(["question", "answer"]),
"gpt_similarity": set(["question", "answer", "ground_truth"]),
"gpt_fluency": set(["question", "answer"]),
"f1_score": set(["answer", "ground_truth"]),
"ada_similarity": set(["answer", "ground_truth"])}
actual_input_cols = set()
for col in expected_input_cols:
if input_data[col] and input_data[col].strip():
actual_input_cols.add(col)
data_validation = selected_metrics
for metric in selected_metrics:
if selected_metrics[metric]:
metric_required_fields = dict_metric_required_fields[metric]
if metric_required_fields <= actual_input_cols:
data_validation[metric] = True
else:
data_validation[metric] = False
return data_validation