o
    ÔÙ¾i'  ã                   @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    )ÚList)ÚTool)ÚBaseFormatDetector)ÚStreamingParseResultc                       sx   e Zd ZdZ‡ fdd„Zdedefdd„Zdedee	 de
fd	d
„Zdedee	 de
f‡ fdd„Zdefdd„Z‡  ZS )ÚJsonArrayParserzñ
    Parser for JSON array tool calls when JSON schema constraints are active.

    This parser is used when tool_choice="required" or a specific tool is named,
    bypassing model-specific parsers in favor of direct JSON array parsing.
    c                    s    t ƒ  ¡  d| _d| _d| _d S )Nú[ú]ú,)ÚsuperÚ__init__Ú	bot_tokenÚ	eot_tokenÚtool_call_separator©Úself©Ú	__class__© ú^/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/function_call/json_array_parser.pyr      s   

zJsonArrayParser.__init__ÚtextÚreturnc                 C   s   d|v pd|v S )z]
        Check if the given text contains a JSON tool call (array or single object).
        r   Ú{r   )r   r   r   r   r   Úhas_tool_call   s   zJsonArrayParser.has_tool_callÚtoolsc                 C   ó   t dƒ‚)zL
        Parse JSON tool calls using the base class implementation.
        z;Detect and parse not supported for JSON schema constraints.©ÚNotImplementedError)r   r   r   r   r   r   Údetect_and_parse   s   ÿz JsonArrayParser.detect_and_parseÚnew_textc                    s   t ƒ  ||¡S )zE
        Streaming incremental parsing with tool validation.
        )r
   Úparse_streaming_increment)r   r   r   r   r   r   r   %   s   z)JsonArrayParser.parse_streaming_incrementc                 C   r   )zÐ
        Return a function that creates StructureInfo for constrained generation.
        This is not used for JSON schema constraints as they are handled
        by the constraint backends directly.
        z3structure_info not used for JSON schema constraintsr   r   r   r   r   Ústructure_info-   s   zJsonArrayParser.structure_info)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚboolr   r   r   r   r   r   Úcallabler    Ú__classcell__r   r   r   r   r      s    ÿÿþr   N)	Útypingr   Ú&sglang.srt.entrypoints.openai.protocolr   Ú-sglang.srt.function_call.base_format_detectorr   Ú#sglang.srt.function_call.core_typesr   r   r   r   r   r   Ú<module>   s
    