o
    h                     @   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                   @   sP   e Zd ZdZdZdZeZeZ	ddgZ
dgZdedef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.text_qatextquestionc                 C   s   t j||d}| j|ddS )N)r   r	   pt)return_tensors)	QA_PROMPTformatpre_processor)selfr   r	   prompt r   `/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/tools/text_question_answering.pyencode'   s   z TextQuestionAnsweringTool.encodec                 C   sT   | j jdi |}|d j\}}|jd }|j||| g|jdd  R  d d S )N	input_ids    r   r   )modelgenerateshapereshape)r   inputs
output_idsin_b_out_br   r   r   forward+   s   
*z!TextQuestionAnsweringTool.forwardc                 C   s   | j j|dddS )NT)skip_special_tokensclean_up_tokenization_spaces)r   decode)r   outputsr   r   r   r"   3   s   z TextQuestionAnsweringTool.decodeN)__name__
__module____qualname__default_checkpointdescriptionnamer   pre_processor_classr   model_classr   r#   strr   r   r"   r   r   r   r   r      s    r   N)models.autor   r   baser   r   r   r   r   r   r   <module>   s   