
    .`i
                         d dl mZ d dlmZ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rd d
lmZ neZ e
e          Z G d de          ZdS )    )Sequence)TYPE_CHECKINGAny)PreTrainedTokenizerBase)DeltaMessage)init_logger)ReasoningParser)DeepSeekR1ReasoningParser   )IdentityReasoningParser)ChatCompletionRequestc                       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d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 )KimiK2ReasoningParsera4  
    Kimi K2 parser that delegates to either DeepSeekR1ReasoningParser or
    IdentityReasoningParser based on `thinking` and `separate_reasoning`.

    Unlike DeepSeekV3ReasoningParser which defaults to NOT thinking,
    KimiK2ReasoningParser defaults to thinking mode (uses DeepSeekR1ReasoningParser).
    	tokenizerc                     t                      j        |g|R i | |                    di           pi }t          |                    dd                    }|rt	          |g|R i || _        d S t          |g|R i || _        d S )Nchat_template_kwargsthinkingT)super__init__popboolr
   _parserr   )selfr   argskwargschat_kwargsr   	__class__s         {/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/reasoning/kimi_k2_reasoning_parser.pyr   zKimiK2ReasoningParser.__init__$   s    4T444V444jj!7<<B
D99:: 	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&KimiK2ReasoningParser.is_reasoning_end0   s    |,,Y777r   	delta_idsc                 8    | j                             ||          S r#   )r   is_reasoning_end_streaming)r   r    r&   s      r   r(   z0KimiK2ReasoningParser.is_reasoning_end_streaming3   s     |66y)LLLr   c                 6    | j                             |          S r#   )r   extract_content_idsr%   s     r   r*   z)KimiK2ReasoningParser.extract_content_ids8   s    |//	:::r   model_outputrequestr   Nc                 8    | j                             ||          S r#   )r   extract_reasoning)r   r+   r,   s      r   r.   z'KimiK2ReasoningParser.extract_reasoning;   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/   r0   r1   r2   r3   r4   s          r   r6   z1KimiK2ReasoningParser.extract_reasoning_streaming@   s0     |77
 
 	
r   )__name__
__module____qualname____doc__r   r   r   intr   r$   listr(   r*   strtupler.   r   r6   __classcell__)r   s   @r   r   r      s        
O"9 
O 
O 
O 
O 
O 
O8(3- 8D 8 8 8 8McM/3CyM	M M M M
;T#Y ;49 ; ; ; ;EE*AE	sTz3:%	&E E E E


 
 	

 %SM
 $C=
 "#
 
	
 
 
 
 
 
 
 
r   r   N)collections.abcr   typingr   r   transformersr   'vllm.entrypoints.openai.engine.protocolr   vllm.loggerr   vllm.reasoningr	   +vllm.reasoning.deepseek_r1_reasoning_parserr
   identity_reasoning_parserr   0vllm.entrypoints.openai.chat_completion.protocolr   r7   loggerr    r   r   <module>rK      s   % $ $ $ $ $ % % % % % % % % 0 0 0 0 0 0 @ @ @ @ @ @ # # # # # # * * * * * * Q Q Q Q Q Q > > > > > >           
X		5
 5
 5
 5
 5
O 5
 5
 5
 5
 5
r   