
    .`i
                     F    d dl mZ d dlmZ d dlmZ  G d de          ZdS )    )ChatCompletionRequest)ResponsesRequest)BaseThinkingReasoningParserc            	           e Zd ZdZedefd            Zedefd            Zdedee	z  de
edz  edz  f         fdZdS )	Qwen3ReasoningParserau  
    Reasoning parser for the Qwen3 model.

    The Qwen3 model uses <think>...</think> tokens to denote reasoning text
    within its output. The model provides a strict switch to disable reasoning
    output via the 'enable_thinking=False' parameter. This parser extracts the
    reasoning content enclosed by <think> and </think> tokens from the model's
    output.
    returnc                     dS )z(The token that starts reasoning content.z<think> selfs    y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/vllm/reasoning/qwen3_reasoning_parser.pystart_tokenz Qwen3ReasoningParser.start_token   s	     y    c                     dS )z&The token that ends reasoning content.z</think>r
   r   s    r   	end_tokenzQwen3ReasoningParser.end_token   s	     zr   model_outputrequestNc                     | j         |vs	| j        |vrd|fS |                    | j                   }|d         r|d         n|d         }| j        |vrd|fS |                    | j                  \  }}}|pd}||fS )a  
        Extract reasoning content from the model output.

        Qwen3 has stricter requirements - it needs both start and end tokens
        to be present, unlike other models that work with just the end token.

        For text <think>abc</think>xyz:
        - 'abc' goes to reasoning
        - 'xyz' goes to content

        Returns:
            tuple[Optional[str], Optional[str]]: reasoning content and content
        N      r   )r   r   	partition)r   r   r   model_output_parts	reasoning_contentfinal_contents           r   extract_reasoningz&Qwen3ReasoningParser.extract_reasoning"   s    $ <//4>3U3U%% *33D4DEE%7%:Uq!!@RST@U 	 >--%% !- 6 6t~ F F	1g4-''r   )__name__
__module____qualname____doc__propertystrr   r   r   r   tupler   r
   r   r   r   r      s          S    X 3    X%(%(*?BR*R%(	sTz3:%	&%( %( %( %( %( %(r   r   N)0vllm.entrypoints.openai.chat_completion.protocolr   *vllm.entrypoints.openai.responses.protocolr   vllm.reasoning.basic_parsersr   r   r
   r   r   <module>r(      s              E D D D D D:( :( :( :( :(6 :( :( :( :( :(r   