o
    
Û¾i
  ã                   @   s8   d dl mZ d dlmZ d dlmZ G dd„ deƒZdS )é    )ÚChatCompletionRequest)ÚResponsesRequest)ÚBaseThinkingReasoningParserc                	   @   s^   e Zd ZdZedefdd„ƒZedefdd„ƒZdedee	B de
ed	B ed	B f fd
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                 C   ó   dS )z(The token that starts reasoning content.z<think>© ©Úselfr   r   úY/home/ubuntu/.local/lib/python3.10/site-packages/vllm/reasoning/qwen3_reasoning_parser.pyÚstart_token   ó   z Qwen3ReasoningParser.start_tokenc                 C   r   )z&The token that ends reasoning content.z</think>r   r	   r   r   r   Ú	end_token   r   zQwen3ReasoningParser.end_tokenÚmodel_outputÚrequestNc                 C   st   | j |vs
| j|vrd|fS | | j ¡}|d r|d n|d }| j|vr)d|fS | | j¡\}}}|p5d}||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_contentr   r   r   Úextract_reasoning"   s   ÿ
z&Qwen3ReasoningParser.extract_reasoning)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚstrr   r   r   r   Útupler   r   r   r   r   r      s    
ÿÿþr   N)Ú0vllm.entrypoints.openai.chat_completion.protocolr   Ú*vllm.entrypoints.openai.responses.protocolr   Úvllm.reasoning.basic_parsersr   r   r   r   r   r   Ú<module>   s   