Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding typed recipe test #1473

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/unitxt/task.py
Original file line number Diff line number Diff line change
@@ -116,13 +116,18 @@ def prepare_args(self):
self.prediction_type
)

if hasattr(self, "inputs") and self.inputs is not None:
self.inputs = self.input_fields

if hasattr(self, "outputs") and self.outputs is not None:
self.outputs = self.reference_fields

def task_deprecations(self):
if hasattr(self, "inputs") and self.inputs is not None:
depr_message = (
"The 'inputs' field is deprecated. Please use 'input_fields' instead."
)
warnings.warn(depr_message, DeprecationWarning, stacklevel=2)

if hasattr(self, "outputs") and self.outputs is not None:
depr_message = "The 'outputs' field is deprecated. Please use 'reference_fields' instead."
warnings.warn(depr_message, DeprecationWarning, stacklevel=2)
39 changes: 36 additions & 3 deletions tests/library/test_artifact.py
Original file line number Diff line number Diff line change
@@ -13,15 +13,16 @@
from unitxt.catalog import add_link_to_catalog, add_to_catalog, get_from_catalog
from unitxt.dataclass import UnexpectedArgumentError
from unitxt.error_utils import UnitxtError
from unitxt.loaders import LoadFromDictionary
from unitxt.loaders import LoadFromDictionary, LoadHF
from unitxt.logging_utils import get_logger
from unitxt.metrics import Accuracy, F1Binary
from unitxt.operator import SequentialOperator
from unitxt.operators import Copy, Rename, Set
from unitxt.processors import StringEquals
from unitxt.settings_utils import get_settings
from unitxt.task import Task
from unitxt.templates import YesNoTemplate
from unitxt.standard import StandardRecipe
from unitxt.task import FormTask, Task
from unitxt.templates import InputOutputTemplate, YesNoTemplate
from unitxt.test_utils.catalog import temp_catalog

from tests.utils import UnitxtTestCase
@@ -614,3 +615,35 @@ def test_artifact_is_gotten_from_catalog_first_hand(self):
card2.task.metrics,
["metrics.f1_micro", "metrics.accuracy", "metrics.f1_macro"],
)

def test_typed_recipe_to_catalog(self):
loader = LoadHF(path="resources/some_path", split="test")
inputs = {"question": "str", "metadata": "List[Dict[str, Any]]"}
outputs = {"answer": "str"}
task = FormTask(
inputs=inputs,
outputs=outputs,
metrics=["metrics.jaccard_index"],
)
templates = [
InputOutputTemplate(
input_format="{question}",
output_format="{answer}",
)
]
preprocessors = ["operators.literal_eval[field=metadata]"]
card = TaskCard(
loader=loader,
task=task,
templates=templates,
preprocess_steps=preprocessors,
)
recipe = StandardRecipe(
card=card,
template_card_index=0,
postprocessors=[
"operators.regex_parser[field=prediction, regex=\\d+]",
"processors.to_list_by_comma_from_references",
],
)
add_to_catalog(recipe, "temp_recipe_name", overwrite=True)