o
    ॵi	                     @   s   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d d	lmZ d
gZejejejdG dd
 d
eZdS )    )DictUnion)	Pipelines)Model)SpaceForDialogModeling)
OutputKeys)PipelineTensor)	PIPELINES)DialogModelingPreprocessor)TasksDialogModelingPipeline)module_namec                	       sb   e Zd Z				ddeeef dededef fdd	Zd
eee	f deeef fddZ
  ZS )r   NgpuTmodelpreprocessorconfig_filedevicec                    s<   t  j|||||d |du rt| jjfi || _dS dS )a  Use `model` and `preprocessor` to create a dialog modeling pipeline for dialog response generation

        Args:
            model (str or SpaceForDialogModeling): Supply either a local model dir or a model id from the model hub,
            or a SpaceForDialogModeling instance.
            preprocessor (DialogModelingPreprocessor): An optional preprocessor instance.
            kwargs (dict, `optional`):
                Extra kwargs passed into the preprocessor's constructor.
        )r   r   r   r   auto_collateN)super__init__r   r   	model_dirr   )selfr   r   r   r   r   kwargs	__class__ e/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/pipelines/nlp/dialog_modeling_pipeline.pyr      s   zDialogModelingPipeline.__init__inputsreturnc                 C   sF   | j jj|d }t|dksJ |dt|d  }||tj< |S )zprocess the prediction results

        Args:
            inputs (Dict[str, Any]): _description_

        Returns:
            Dict[str, str]: the prediction results
        resp      )r   
text_field	tokenizerconvert_ids_to_tokenslenr   OUTPUT)r   r   sys_rspr   r   r   postprocess/   s   
	
z"DialogModelingPipeline.postprocess)NNr   T)__name__
__module____qualname__r   r   strr   r   r   r	   r)   __classcell__r   r   r   r   r      s    
*N)typingr   r   modelscope.metainfor   modelscope.modelsr   modelscope.models.nlpr   modelscope.outputsr   modelscope.pipelines.baser   r	   modelscope.pipelines.builderr
   modelscope.preprocessorsr   modelscope.utils.constantr   __all__register_moduletask_oriented_conversationdialog_modelingr   r   r   r   r   <module>   s   