o
    ÔÙ¾i%  ã                   @   sV   d dl 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 )é    N)ÚList)ÚTool)ÚStreamingParseResult)ÚQwen25Detectorc                       sx   e Zd ZdZdedefdd„Zdedef‡ fdd„Zdedee	 de
f‡ fd	d
„Zdedee	 de
f‡ fdd„Z‡  ZS )ÚTrinityDetectora;  
    Detector for Trinity models using Qwen-style function call format.

    This detector extends Qwen25Detector to handle tool calls that may appear
    inside <think> sections by stripping the think tags before parsing.

    Reference: https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct?chat_template=default
    ÚtextÚreturnc                 C   s   |  dd¡  dd¡S )z=Remove <think> and </think> tags, keeping the content inside.z<think>Ú z</think>)Úreplace©Úselfr   © r   ú]/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/function_call/trinity_detector.pyÚ_strip_think_tags   s   z!TrinityDetector._strip_think_tagsc                    s   t ƒ  |  |¡¡S )z'Check if the text contains a tool call.)ÚsuperÚhas_tool_callr   r   ©Ú	__class__r   r   r      s   zTrinityDetector.has_tool_callÚtoolsc                    ó   t ƒ  |  |¡|¡S )zW
        One-time parsing: Detects and parses tool calls in the provided text.
        )r   Údetect_and_parser   )r   r   r   r   r   r   r      s   z TrinityDetector.detect_and_parseÚnew_textc                    r   )z?
        Streaming incremental parsing for tool calls.
        )r   Úparse_streaming_incrementr   )r   r   r   r   r   r   r   #   s   
ÿz)TrinityDetector.parse_streaming_increment)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   Úboolr   r   r   r   r   r   Ú__classcell__r   r   r   r   r      s    	ÿÿþr   )ÚloggingÚtypingr   Ú&sglang.srt.entrypoints.openai.protocolr   Ú#sglang.srt.function_call.core_typesr   Ú(sglang.srt.function_call.qwen25_detectorr   Ú	getLoggerr   Úloggerr   r   r   r   r   Ú<module>   s    
