o
    *j	                     @   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   Z	model_dirr   )selfr   r   r   r   r   kwargs	__class__ r/var/www/html/Deteccion_Ine/venv/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   Z
text_field	tokenizerZconvert_ids_to_tokenslenr   ZOUTPUT)r   r   Z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   Zmodelscope.metainfor   Zmodelscope.modelsr   Zmodelscope.models.nlpr   Zmodelscope.outputsr   Zmodelscope.pipelines.baser   r	   Zmodelscope.pipelines.builderr
   Zmodelscope.preprocessorsr   Zmodelscope.utils.constantr   __all__Zregister_moduleZtask_oriented_conversationZdialog_modelingr   r   r   r   r   <module>   s   