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
28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
from promptflow.core import tool
|
|
|
|
|
|
def is_valid(input_item):
|
|
return True if input_item and input_item.strip() else False
|
|
|
|
|
|
@tool
|
|
def validate_input(question: str, answer: str, documents: str, selected_metrics: dict) -> dict:
|
|
input_data = {"question": is_valid(question), "answer": is_valid(answer), "documents": is_valid(documents)}
|
|
expected_input_cols = set(input_data.keys())
|
|
dict_metric_required_fields = {"gpt_groundedness": set(["question", "answer", "documents"]),
|
|
"gpt_relevance": set(["question", "answer", "documents"]),
|
|
"gpt_retrieval_score": set(["question", "documents"])}
|
|
actual_input_cols = set()
|
|
for col in expected_input_cols:
|
|
if input_data[col]:
|
|
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
|