From 5e080c11bf5ff2cded1e4eceaeb6eb49c9e99e97 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Wed, 16 Nov 2022 09:51:12 +0100 Subject: [PATCH] Updating the doctest for conversational. (#20236) * Updating the doctest for conversational. - Make it tested against - Add explicit output in the test. * Removing assert. * Adding missing link. --- src/transformers/pipelines/conversational.py | 36 +++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/transformers/pipelines/conversational.py b/src/transformers/pipelines/conversational.py index 0f8a41ebfd..e4e4587fda 100644 --- a/src/transformers/pipelines/conversational.py +++ b/src/transformers/pipelines/conversational.py @@ -164,6 +164,25 @@ class ConversationalPipeline(Pipeline): """ Multi-turn conversational pipeline. + Example: + + ```python + >>> from transformers import pipeline, Conversation + + >>> chatbot = pipeline(model="microsoft/DialoGPT-medium") + >>> conversation = Conversation("Going to the movies tonight - any suggestions?") + >>> conversation = chatbot(conversation) + >>> conversation.generated_responses[-1] + 'The Big Lebowski' + + >>> conversation.add_user_input("Is it an action movie?") + >>> conversation = chatbot(conversation) + >>> conversation.generated_responses[-1] + "It's a comedy." + ``` + + [Using pipelines in a webserver or with a dataset](../pipeline_tutorial) + This conversational pipeline can currently be loaded from [`pipeline`] using the following task identifier: `"conversational"`. @@ -171,22 +190,7 @@ class ConversationalPipeline(Pipeline): currently: *'microsoft/DialoGPT-small'*, *'microsoft/DialoGPT-medium'*, *'microsoft/DialoGPT-large'*. See the up-to-date list of available models on [huggingface.co/models](https://huggingface.co/models?filter=conversational). - - Usage: - - ```python - conversational_pipeline = pipeline("conversational") - - conversation_1 = Conversation("Going to the movies tonight - any suggestions?") - conversation_2 = Conversation("What's the last book you have read?") - - conversational_pipeline([conversation_1, conversation_2]) - - conversation_1.add_user_input("Is it an action movie?") - conversation_2.add_user_input("What is the genre of this book?") - - conversational_pipeline([conversation_1, conversation_2]) - ```""" + """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)