Skip to content

Commit

Permalink
Deprecate conversation support in TextGeneration in favour of `Chat…
Browse files Browse the repository at this point in the history
…Generation` (#676)

* Deprecate conversation support in `TextGeneration`

* Fix linting issue from `develop` merge
  • Loading branch information
alvarobartt authored May 29, 2024
1 parent c9623fc commit bce7da1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/distilabel/distiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_distiset( # noqa: C901
correspond to different configurations of the dataset.
"""
from distilabel.steps.constants import DISTILABEL_METADATA_KEY

logger = logging.getLogger("distilabel.distiset")

data_dir = Path(data_dir)
Expand Down
8 changes: 2 additions & 6 deletions src/distilabel/steps/tasks/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,10 @@ def format_input(self, input: Dict[str, Any]) -> ChatType:
is the first interaction from the user within a conversation."""

if is_openai_format(input["instruction"]):
warnings.warn(
raise ValueError(
"Providing `instruction` formatted as an OpenAI chat / conversation is"
" about to be deprecated in `distilabel v1.2.0`, please make sure to use"
" `ChatTextGeneration` with `messages` as input instead.",
DeprecationWarning,
stacklevel=2,
" deprecated, you should use `ChatGeneration` with `messages` as input instead.",
)
return input["instruction"]

if not isinstance(input["instruction"], str):
raise ValueError(
Expand Down
23 changes: 6 additions & 17 deletions tests/unit/steps/tasks/test_text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def test_format_input_errors(self) -> None:
name="task", llm=llm, pipeline=pipeline, use_system_prompt=True
)

with pytest.raises(
ValueError,
match=r"Providing \`instruction\` formatted as an OpenAI chat / conversation is deprecated",
):
task.format_input({"instruction": [{"role": "user", "content": "test"}]})

with pytest.raises(
ValueError, match=r"Input \`instruction\` must be a string. Got: 1."
):
Expand All @@ -79,23 +85,6 @@ def test_process(self) -> None:
}
]

def test_deprecation_warning(self) -> None:
pipeline = Pipeline(name="unit-test-pipeline")
llm = DummyLLM()
task = TextGeneration(name="task", llm=llm, pipeline=pipeline)

with pytest.warns(
DeprecationWarning,
match=r"Providing \`instruction\` formatted as an OpenAI chat \/ conversation is about to be deprecated in \`distilabel v1.2.0\`",
):
task.format_input(
{
"instruction": [
{"role": "user", "content": "Tell me a joke."},
]
}
)


class TestChatGeneration:
def test_format_input(self) -> None:
Expand Down

0 comments on commit bce7da1

Please sign in to comment.