o
    á)iÇ	  ã                   @   sz   d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ eeƒZe d¡G dd	„ d	eƒƒZd
S )é    )ÚSequence)ÚOptionalÚUnion)ÚPreTrainedTokenizerBase)ÚChatCompletionRequestÚDeltaMessage)Úinit_logger)ÚReasoningParserÚReasoningParserManagerZGptOssc                       s¶   e Zd ZdZdef‡ fdd„Zdee defdd„Z	dee dee fd	d
„Z
dedededee dee dee deedf fdd„Zdededeee ee f fdd„Z‡  ZS )ÚGptOssReasoningParserz½
    Reasoning parser for GptOss model.

    The GptOss model uses harmony to extract reasoning content and this parser
    is only used for detecting the end of the reasoning content.
    Ú	tokenizerc                    s   t ƒ  |¡ | j d¡| _d S )Nz-<|start|>assistant<|channel|>final<|message|>)ÚsuperÚ__init__Zmodel_tokenizerÚencodeÚreasoning_end_token_ids)Úselfr   ©Ú	__class__© úr/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/vllm/reasoning/gptoss_reasoning_parser.pyr      s   
ÿzGptOssReasoningParser.__init__Ú	input_idsÚreturnc                 C   sZ   | j }t|ƒdksJ dƒ‚tt|ƒt|ƒ ddƒD ]}|||t|ƒ … |kr* dS qdS )Nr   z reasoning_end_token_ids is emptyéÿÿÿÿTF)r   ÚlenÚrange)r   r   Zend_token_idsÚir   r   r   Úis_reasoning_end   s   ÿz&GptOssReasoningParser.is_reasoning_endc                 C   ó   t dƒ‚©Nz[GptOss model uses harmony to extract reasoning content. This function should not be called.©ÚRuntimeError)r   r   r   r   r   Úextract_content_ids)   s   ÿz)GptOssReasoningParser.extract_content_idsÚprevious_textÚcurrent_textÚ
delta_textÚprevious_token_idsÚcurrent_token_idsÚdelta_token_idsNc                 C   r   r   r   )r   r"   r#   r$   r%   r&   r'   r   r   r   Ú#extract_reasoning_content_streaming.   s   	ÿz9GptOssReasoningParser.extract_reasoning_content_streamingÚmodel_outputÚrequestc                 C   r   r   r   )r   r)   r*   r   r   r   Úextract_reasoning_content;   s   ÿz/GptOssReasoningParser.extract_reasoning_content)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚlistÚintÚboolr   r!   Ústrr   r   r   r(   r   Útupler   r+   Ú__classcell__r   r   r   r   r      s6    
þýüûúù

øÿÿþr   N)Úcollections.abcr   Útypingr   r   Ztransformersr   Z vllm.entrypoints.openai.protocolr   r   Zvllm.loggerr   Zvllm.reasoningr	   r
   r,   ÚloggerZregister_moduler   r   r   r   r   Ú<module>   s   