U
    9%e                     @   s4   d dl mZmZ ddlmZ dZG dd deZdS )   )AutoModelForSeq2SeqLMAutoTokenizer   )PipelineToolzxHere is a text containing a lot of information: '''{text}'''.

Can you answer this question about the text: '{question}'c                   @   sN   e Zd ZdZdZdZeZeZ	ddgZ
dgZeedddZdd	 Zd
d ZdS )TextQuestionAnsweringToolzgoogle/flan-t5-basezThis is a tool that answers questions related to a text. It takes two arguments named `text`, which is the text where to find the answer, and `question`, which is the question, and returns the answer to the question.Ztext_qatextr   questionc                 C   s   t j||d}| j|ddS )Nr   pt)Zreturn_tensors)	QA_PROMPTformatpre_processor)selfr   r	   prompt r   i/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/tools/text_question_answering.pyencode'   s    z TextQuestionAnsweringTool.encodec                 C   sN   | j jf |}|d j\}}|jd }|j||| f|jdd   d d S )NZ	input_ids    r   )modelgenerateshapeZreshape)r   inputsZ
output_idsZin_b_Zout_br   r   r   forward+   s    
z!TextQuestionAnsweringTool.forwardc                 C   s   | j j|dddS )NT)Zskip_special_tokensZclean_up_tokenization_spaces)r   decode)r   outputsr   r   r   r   3   s    z TextQuestionAnsweringTool.decodeN)__name__
__module____qualname__Zdefault_checkpointdescriptionnamer   Zpre_processor_classr   Zmodel_classr   r   strr   r   r   r   r   r   r   r      s   r   N)Zmodels.autor   r   baser   r   r   r   r   r   r   <module>   s   