You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportList, UnionfromtransformersimportConversationalPipelineclassCustomConversationalPipeline(ConversationalPipeline):
def__call__(self, conversations: Union[Conversation, List[Conversation]], num_workers=0, **kwargs):
r""" Generate responses for the conversation(s) given as inputs. Args: conversations (a :class:`~transformers.Conversation` or a list of :class:`~transformers.Conversation`): Conversations to generate responses for. clean_up_tokenization_spaces (:obj:`bool`, `optional`, defaults to :obj:`False`): Whether or not to clean up the potential extra spaces in the text output. generate_kwargs: Additional keyword arguments to pass along to the generate method of the model (see the generate method corresponding to your framework `here <./model.html#generative-models>`__). Returns: :class:`~transformers.Conversation` or a list of :class:`~transformers.Conversation`: Conversation(s) with updated generated responses for those containing a new user input. """ifisinstance(conversations, str):
conversations= [
{'role': 'user', 'content': conversations}
]
# XXX: num_workers==0 is required to be backward compatible# Otherwise the threads will require a Conversation copy.# This will definitely hinder performance on GPU, but has to be opted# in because of this BC change.outputs=super().__call__(conversations, num_workers=num_workers, **kwargs)
ifisinstance(outputs, list) andlen(outputs) ==1:
returnoutputs[0]
returnoutputs
Hi @mattdeeperinsights, we're actually deprecating the ConversationalPipeline in favour of the TextGenerationPipeline. ConversationalPipeline will be removed in the very near future, but you can now pass chats directly to TextGenerationPipeline instead.
Unfortunately, this means that your shortcut won't work that well - I think it would have been reasonably clean for ConversationalPipeline, but TextGenerationPipeline interprets a single string as a naked string to be completed, rather than a user message.
Feature request
Currently
ConversationalPipeline
expects aconversation
as input (a list of custom objects).Sometimes, you may want to quickly feed in a piece of text as a simple
str
to a conversation model without wrapping up first.Motivation
I think this would simplify the process of trying out chat based models and ensuring that we call them with the correct format etc.
Your contribution
Currently, I can easily get around this by updating the
ConversationalPipeline.__call__
method by handling the case thatconversations
is astr
:Full workable solution is then:
The text was updated successfully, but these errors were encountered: