
    .`i                         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
e	          ZdS )    )Sequence)ChatCompletionRequest)DeltaMessage)init_logger)ReasoningParser)DeepSeekR1ReasoningParser)IdentityReasoningParser)TokenizerLikec                       e Zd ZdZdef fdZdee         defdZ	dee         dee         defdZ
dee         dee         fd	Zd
ededeedz  edz  f         fdZdedededee         dee         dee         dedz  fdZ x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                 b    t                      j        |g|R i | |                    di           pi }t          |                    dd                    }t          |                    dd                    }|o|}|rt	          |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__s          y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/reasoning/holo2_reasoning_parser.pyr   zHolo2ReasoningParser.__init__+   s    4T444V444jj!7<<B 
D99::{/@$GGHH/ 	O4YPPPPPPDLLL29NtNNNvNNDLLL    	input_idsreturnc                 6    | j                             |          S N)r   is_reasoning_endr   r   s     r   r"   z%Holo2ReasoningParser.is_reasoning_end<   s    |,,Y777r   	delta_idsc                 8    | j                             ||          S r!   )r   is_reasoning_end_streaming)r   r   r$   s      r   r&   z/Holo2ReasoningParser.is_reasoning_end_streaming?   s     |66y)LLLr   c                 6    | j                             |          S r!   )r   extract_content_idsr#   s     r   r(   z(Holo2ReasoningParser.extract_content_idsD   s    |//	:::r   model_outputrequestNc                 8    | j                             ||          S r!   )r   extract_reasoning)r   r)   r*   s      r   r,   z&Holo2ReasoningParser.extract_reasoningG   s     |--lGDDDr   previous_textcurrent_text
delta_textprevious_token_idscurrent_token_idsdelta_token_idsc                 @    | j                             ||||||          S r!   )r   extract_reasoning_streaming)r   r-   r.   r/   r0   r1   r2   s          r   r4   z0Holo2ReasoningParser.extract_reasoning_streamingL   s0     |77
 
 	
r   )__name__
__module____qualname____doc__r
   r   r   intr   r"   r&   listr(   strr   tupler,   r   r4   __classcell__)r   s   @r   r   r      s        *O- O O O O O O"8(3- 8D 8 8 8 8M!#M3;C=M	M M M M
;T#Y ;49 ; ; ; ;EE*?E	sTz3:%	&E E E E


 
 	

 %SM
 $C=
 "#
 
	
 
 
 
 
 
 
 
r   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
   r5   loggerr    r   r   <module>rH      s   % $ $ $ $ $      A @ @ @ @ @ # # # # # #      R Q Q Q Q Q L L L L L L ) ) ) ) ) )	X		G
 G
 G
 G
 G
? G
 G
 G
 G
 G
r   