o
    -i                     @   s|   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	 d dl
mZ d dlmZ d dlmZ eeZG d	d
 d
e	ZdS )    )Sequence)ChatCompletionRequest)DeltaMessage)init_logger)ReasoningParser)DeepSeekR1ReasoningParser)IdentityReasoningParser)TokenizerLikec                       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 defd
dZ
dee dee fddZdededeedB edB f fddZdedededee dee dee dedB fddZ  ZS )Holo2ReasoningParsera  
    Reasoning parser for the Holo2 models which are based on Qwen3.

    The Holo2 model uses <think>...</think> tokens to denote reasoning text but <think>
    is part of the chat template. This parser extracts the reasoning content until
    </think> in the model's output.

    The model provides a switch to enable or disable reasoning
    output via the 'thinking=False' parameter.

    Chat template args:
    - thinking: Whether to enable reasoning output (default: True)


    Parsing rules on model output:
        - thinking == False
            -> Model output is treated as purely the content |content|
        - thinking == True
            -> Model output is |reasoning_content|</think>|content|
    	tokenizerc                    s   t  j|g|R i | |di pi }t|dd}t|dd}|o(|}|r9t|g|R i || _d S t|g|R i || _d S )Nchat_template_kwargsthinkingTenable_thinking)super__init__getboolr   _parserr   )selfr   argskwargschat_kwargsr   r   	__class__ b/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/reasoning/holo2_reasoning_parser.pyr   +   s   zHolo2ReasoningParser.__init__	input_idsreturnc                 C      | j |S N)r   is_reasoning_endr   r   r   r   r   r    <      z%Holo2ReasoningParser.is_reasoning_end	delta_idsc                 C      | j ||S r   )r   is_reasoning_end_streaming)r   r   r#   r   r   r   r%   ?      z/Holo2ReasoningParser.is_reasoning_end_streamingc                 C   r   r   )r   extract_content_idsr!   r   r   r   r'   D   r"   z(Holo2ReasoningParser.extract_content_idsmodel_outputrequestNc                 C   r$   r   )r   extract_reasoning)r   r(   r)   r   r   r   r*   G   r&   z&Holo2ReasoningParser.extract_reasoningprevious_textcurrent_text
delta_textprevious_token_idscurrent_token_idsdelta_token_idsc                 C   s   | j ||||||S r   )r   extract_reasoning_streaming)r   r+   r,   r-   r.   r/   r0   r   r   r   r1   L   s   	z0Holo2ReasoningParser.extract_reasoning_streaming)__name__
__module____qualname____doc__r	   r   r   intr   r    r%   listr'   strr   tupler*   r   r1   __classcell__r   r   r   r   r
      sD    

r
   N)collections.abcr   0vllm.entrypoints.openai.chat_completion.protocolr   'vllm.entrypoints.openai.engine.protocolr   vllm.loggerr   vllm.reasoningr   +vllm.reasoning.deepseek_r1_reasoning_parserr   (vllm.reasoning.identity_reasoning_parserr   vllm.tokenizersr	   r2   loggerr
   r   r   r   r   <module>   s   