Skip to content

Commit

Permalink
Fix to be more genral
Browse files Browse the repository at this point in the history
Signed-off-by: elronbandel <elronbandel@gmail.com>
  • Loading branch information
elronbandel committed Nov 17, 2024
1 parent 5f2501c commit e898cf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 9 additions & 4 deletions src/unitxt/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,15 @@ def prepare(self):
), f"Specify either template ({self.template}) or template_card_index ({self.template_card_index}) but not both"

if self.template_card_index is None and self.template is None:
self.template_card_index = 0
logger.warning(
"Template was not specified in recipe, using template_card_index=0 by default."
)
if self.card is not None:
self.template_card_index = next(iter(self.card.templates))
logger.warning(
"Template was not specified in recipe, using the first template from the card by default."
)
else:
raise ValueError(
"Specify a template or template_card_index, or a card to get a default template from."
)

if self.template_card_index is not None:
try:
Expand Down
7 changes: 0 additions & 7 deletions tests/library/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,6 @@ def test_standard_recipe_with_no_test(self):
self.assertTrue(len(results) > 0)

def test_standard_recipe_with_template_errors(self):
# Check some template was specified
with self.assertRaises(AssertionError) as cm:
StandardRecipeWithIndexes(card="cards.wnli")
self.assertEqual(
str(cm.exception), "Specify either template or template_card_index in card"
)

# Check either template or template index was specified , but not both
with self.assertRaises(AssertionError) as cm:
StandardRecipeWithIndexes(
Expand Down

0 comments on commit e898cf3

Please sign in to comment.