§
    ÚŽ’jøW  ã                   ó(  — d Z ddlZddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZmZ ddlmZ dd	lmZ d
dlmZmZ d
dlmZmZ d
dlmZ ddlmZ ddlmZm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'Z' erddl(m)Z) ddl*m+Z+ neZ)eZ+ G d„ de¦  «        Z,dS )zBThe DashScope chat model class (OpenAI-compatible implementation).é    N)ÚOrderedDict)Údatetime)ÚAnyÚAsyncGeneratorÚListÚLiteralÚTypeÚTYPE_CHECKING)Ú	BaseModelÚFieldé   )Ú_build_streaming_wav_header)Ú_generate_idé   )ÚChatModelBaseÚ_TOOL_CHOICE_LITERAL_MODES)ÚChatResponseÚStructuredResponse)Ú	ChatUsage)ÚDashScopeCredential)ÚFormatterBaseÚDashScopeChatFormatter)ÚMsgÚ	TextBlockÚThinkingBlockÚToolCallBlock)Ú
ToolChoice)ÚChatCompletion)ÚAsyncStreamc                   ó(  ‡ — e Zd ZU dZ G d„ de¦  «        ZdZed         ed<   	 	 	 	 	 	 	 	 d&de	de
dddedededededz  dee
ef         dz  ddfˆ fd„Zedeee         df         fd„¦   «         Z	 	 d'de
dee         dee         dz  dedz  dedeeedf         z  fd„Zded edeedf         fd!„Zded e defd"„Z!dee         dz  dedz  deee         dz  e
ez  dz  f         fd#„Z"	 d(de
dee         d$ee         ez  dedz  dede#fˆ fd%„Z$ˆ xZ%S ))ÚDashScopeChatModela*  The DashScope chat model (OpenAI-compatible implementation).

    This implementation uses the OpenAI Python SDK to call DashScope's
    OpenAI-compatible endpoint (``compatible-mode/v1``), which supports
    both text-only and multimodal (image/video) inputs through the same
    unified API.
    c                   óx  — e Zd ZU dZ edddd¬¦  «        Zedz  ed<    edd	d
¬¦  «        Ze	ed<    edddd¬¦  «        Z
edz  ed<    eddddd¬¦  «        Zedz  ed<    eddddd¬¦  «        Zedz  ed<    eddddd¬¦  «        Zedz  ed<    eddd ¬¦  «        Ze	ed!<    edd"d#¬¦  «        Zedz  ed$<   dS )%úDashScopeChatModel.Parametersz%The parameters for DashScope LLM API.Nz
Max Tokensz0The maximum number of tokens for the LLM output.r   )ÚdefaultÚtitleÚdescriptionÚgtÚ
max_tokensFÚThinkingz'The thinking enable for the LLM output.)r$   r%   r&   Úthinking_enablezThinking Budgetz'The thinking budget for the LLM output.Úthinking_budgetÚTemperaturez#The temperature for the LLM output.r   )r$   r%   r&   ÚgeÚltÚtemperaturezTop Pz#The top P value for the LLM output.é   )r$   r%   r&   r'   ÚleÚtop_pzTop Kz#The top K value for the LLM output.éd   Útop_kTzParallel Tool Callsz1If enable parallel tool calls for the LLM output.Úparallel_tool_callsÚVoiceus  Voice for audio output on omni-style models (e.g. ``qwen3.5-omni-plus``). Setting this implicitly asks the model to speak its response â€” ``modalities`` is filled in automatically. Supported voices vary by model â€” see the model card's ``voice.suggestions``. Any value the API accepts works â€” the suggestions are convenience-only. Leave unset for text-only responses.Úvoice)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   ÚintÚ__annotations__r*   Úboolr+   r/   Úfloatr2   r4   r5   r7   Ústr© ó    úPC:\Projects\DSCons\.venv\Lib\site-packages\agentscope\model\_dashscope\_model.pyÚ
Parametersr#   +   sÝ  € € € € € € Ø3Ð3à!& ØØØJØð	"
ñ "
ô "
ˆ
�C˜$‘Jð 	
ð 	
ñ 	
ð !& ØØØAð!
ñ !
ô !
ˆ˜ð 	
ð 	
ñ 	
ð ', eØØ#ØAØð	'
ñ '
ô '
ˆ˜˜t™ð 	
ð 	
ñ 	
ð %* EØØØ=ØØð%
ñ %
ô %
ˆ�U˜T‘\ð 	
ð 	
ñ 	
ð $˜eØØØ=ØØð
ñ 
ô 
ˆˆu�t‰|ð 	
ð 	
ñ 	
ð "˜EØØØ=ØØð
ñ 
ô 
ˆˆs�T‰zð 	
ð 	
ñ 	
ð %* EØØ'ØKð%
ñ %
ô %
Ð˜Tð 	
ð 	
ñ 	
ð "˜EØØðð	
ñ 
ô 
ˆˆs�T‰zð 	
ð 	
ñ 	
ð 	
ð 	
rB   rD   Údashscope_chatÚtypeNTr   ç      ð?é   Ú
credentialÚmodelÚ
parametersz$DashScopeChatModel.Parameters | NoneÚstreamÚmax_retriesÚretry_delayÚcontext_sizeÚ	formatterÚclient_kwargsÚreturnc
           	      óD  •— t          ¦   «                              |||p|                      ¦   «         ||||¬¦  «         |pt          ¦   «         | _        |	pi | _        ddl}
 |
j        d| j        j	         
                    ¦   «         | j        j        dœ| j        ¤Ž| _        dS )a˜  Initialize the DashScope chat model.

        Args:
            credential (`DashScopeCredential`):
                The DashScope credential used to authenticate API calls.
            model (`str`):
                The DashScope model name, e.g. ``qwen-plus``.
            parameters (`DashScopeChatModel.Parameters | None`, defaults to             `None`):
                The DashScope API parameters. When ``None``, the default
                parameters will be used.
            stream (`bool`, defaults to `True`):
                Whether to enable streaming output.
            max_retries (`int`, defaults to `3`):
                The maximum number of retries for the DashScope API.
            retry_delay (`float`, defaults to `1.0`):
                Seconds to sleep between retry attempts.
            context_size (`int`, defaults to `131072`):
                The model context size used for context compression.
            formatter (`FormatterBase | None`, defaults to `None`):
                The formatter that converts ``Msg`` objects to the format
                required by the DashScope API. When ``None``, a
                ``DashScopeChatFormatter`` instance will be used.
            client_kwargs (`dict[str, Any] | None`, defaults to `None`):
                Extra keyword arguments forwarded to ``openai.AsyncClient``
                (e.g. ``timeout``, ``default_headers``, ``http_client``).
        )rI   rJ   rK   rL   rM   rN   rO   r   N)Úapi_keyÚbase_urlrA   )ÚsuperÚ__init__rD   r   rP   rQ   ÚopenaiÚAsyncClientrI   rT   Úget_secret_valuerU   Úclient)ÚselfrI   rJ   rK   rL   rM   rN   rO   rP   rQ   rX   Ú	__class__s              €rC   rW   zDashScopeChatModel.__init__r   sÃ   ø€ õN 	‰Œ×ÒØ!ØØ!Ð6 T§_¢_Ñ%6Ô%6ØØ#Ø#Ø%ð 	ñ 	
ô 	
ð 	
ð #Ð>Õ&<Ñ&>Ô&>ˆŒØ*Ð0¨bˆÔàˆˆˆà*<¨&Ô*<ð +
Ø”OÔ+×<Ò<Ñ>Ô>Ø”_Ô-ð+
ð +
ð Ô ð+
ð +
ˆŒˆˆrB   .c                 ó>   — dd l }|j        |j        |j        |j        fS )Nr   )rX   ÚAPIConnectionErrorÚAPITimeoutErrorÚRateLimitErrorÚInternalServerError)ÚclsrX   s     rC   Ú_get_retryable_exceptionsz,DashScopeChatModel._get_retryable_exceptions­   s/   € àˆˆˆð Ô%ØÔ"ØÔ!ØÔ&ð	
ð 	
rB   Ú
model_nameÚmessagesÚtoolsÚtool_choiceÚkwargsc              ‹   óÚ  K  — | j                              |¦  «        ƒ d{V —†}||| j        dœ}| j        j        �| j        j        |d<   | j        j        �| j        j        |d<   | j        j        �| j        j        |d<   | j        j        �| j        j        ddœ|d<   d	dg|d
<   |                     |¦  «         |  	                    ||¦  «        \  }}	|�||d<   | j        j
        sd|d<   |	�|	|d<   i }
| j        j        �| j        j        |
d<   | j        j        �| j        j        |
d<   | j        j        �| j        j        |
d<   |
r1|                     di ¦  «         |d                              |
¦  «         | j        rddi|d<   t          j        ¦   «         } | j        j        j        j        di |¤Žƒ d{V —†}| j        r|                      ||¦  «        S |                      ||¦  «        S )aÑ  Call the DashScope chat completions API via OpenAI-compatible
        endpoint.

        Args:
            model_name (`str`):
                The model name to use for this call.
            messages (`list`):
                The Msg objects that will be formatted and sent to the API.
            tools (`list[dict] | None`, default `None`):
                The tools JSON schemas that the model can use.
            tool_choice (`ToolChoice | None`, default `None`):
                Controls which (if any) tool is called by the model.
            **kwargs (`Any`):
                The keyword arguments for DashScope chat completions API,
                e.g. ``temperature``, ``max_tokens``, ``top_p``, etc.
        N)rJ   rf   rL   r(   r/   r2   Úpcm16)r7   ÚformatÚaudioÚtextÚ
modalitiesrg   Fr5   rh   Úenable_thinkingr+   r4   Ú
extra_bodyÚinclude_usageTÚstream_optionsrA   )rP   rl   rL   rK   r(   r/   r2   r7   ÚupdateÚ_format_toolsr5   r*   r+   r4   Ú
setdefaultr   Únowr[   ÚchatÚcompletionsÚcreateÚ_parse_stream_responseÚ_parse_completion_response)r\   re   rf   rg   rh   ri   Úformatted_messagesÚrequest_kwargsÚ	fmt_toolsÚfmt_tool_choicerq   Ústart_datetimeÚresponses                rC   Ú	_call_apizDashScopeChatModel._call_api¸   sT  è è € ð0 $(¤>×#8Ò#8¸Ñ#BÔ#BÐBÐBÐBÐBÐBÐBÐð  Ø*Ø”kð*
ð *
ˆð Œ?Ô%Ð1Ø+/¬?Ô+EˆN˜<Ñ(àŒ?Ô&Ð2Ø,0¬OÔ,GˆN˜=Ñ)àŒ?Ô Ð,Ø&*¤oÔ&;ˆN˜7Ñ#àŒ?Ô Ð,ð œÔ.Ø!ð'ð 'ˆN˜7Ñ#ð -3°GÐ+<ˆN˜<Ñ(à×Ò˜fÑ%Ô%Ð%à%)×%7Ò%7¸¸{Ñ%KÔ%KÑ"ˆ	�?ØÐ Ø&/ˆN˜7Ñ#Ø”?Ô6ð >Ø8=�Ð4Ñ5ØÐ&Ø,;ˆN˜=Ñ)à%'ˆ
ØŒ?Ô*Ð6Ø,0¬OÔ,KˆJÐ(Ñ)ØŒ?Ô*Ð6Ø,0¬OÔ,KˆJÐ(Ñ)ØŒ?Ô Ð,Ø"&¤/Ô"7ˆJ�wÑàð 	<Ø×%Ò% l°BÑ7Ô7Ð7Ø˜<Ô(×/Ò/°
Ñ;Ô;Ð;àŒ;ð 	GØ0?ÀÐ/FˆNÐ+Ñ,å!œ™œˆØ<˜œÔ)Ô5Ô<ÐNÐN¸~ÐNÐNÐNÐNÐNÐNÐNÐNˆàŒ;ð 	IØ×.Ò.¨~¸xÑHÔHÐHà×.Ò.¨~¸xÑHÔHÐHrB   r�   r‚   c                ó  K  — d}d}t          ¦   «         }t          ¦   «         }t          ¦   «         }t          ¦   «         }t          ¦   «         }	|4 ƒd{V —†}
|
2 3 d{V —†}t          g d|¬¦  «        }t          |dd¦  «        p|}||_        |j        r}|j        }t          |dd¦  «        }|rt          |d¦  «        r
|j        pd}nd}t          |j	        pd|j
        pdt          j        ¦   «         |z
                       ¦   «         |¬¦  «        }|j        s|�||_        |W V — ŒÍ|j        d         }|j        }t          |d	d¦  «        r|                     ||j        ¬
¦  «         t          |dd¦  «        r|                     ||j        ¬¦  «         t          |dd¦  «        pg D ]„}|j        }t          |dd¦  «        }|rt          |dd¦  «        nd}|rt          |dd¦  «        nd}||	vr|j        |pdf|	|<   |	|         \  }}|                     |j        p||p||pd¬¦  «         Œ…t          |dd¦  «        r”t          |dd¦  «        }t-          |t.          ¦  «        r|                     dd¦  «        }nt          |dd¦  «        }|rDt3          j        |¦  «        }|st7          ¦   «         |z   }d}n|}|                     ||d¬¦  «         |j        s|r||_        |W V — �Œ�6 	 ddd¦  «        ƒd{V —† dS # 1 ƒd{V —†swxY w Y   dS )aÛ  Parse the DashScope streaming response (OpenAI-compatible format).

        Args:
            start_datetime (`datetime`):
                The start datetime of the response generation.
            response (`AsyncStream`):
                The OpenAI-compatible async stream object.

        Yields:
            `ChatResponse`:
                Incremental ``ChatResponse`` objects with ``is_last=False``
                followed by a final one with ``is_last=True``.
        FN)ÚcontentÚis_lastÚidr‡   Úprompt_tokens_detailsÚcached_tokensr   ©Úinput_tokensÚoutput_tokensÚtimeÚcache_input_tokensÚreasoning_content)Úblock_idÚthinkingr…   )r�   rn   Ú
tool_callsÚfunctionÚnameÚ	argumentsÚunknownÚ )r�   r”   Úinputrm   ÚdataTz	audio/wav)r�   r™   Ú
media_type)r   r   r   Úgetattrr‡   ÚusageÚhasattrr‰   r   Úprompt_tokensÚcompletion_tokensr   rw   Útotal_secondsÚchoicesÚdeltaÚappend_thinkingr�   Úappend_textr…   ÚindexÚappend_tool_callÚ
isinstanceÚdictÚgetÚbase64Ú	b64decoder   Úappend_data_block)r\   r�   r‚   Úaudio_header_sentrœ   Úresponse_idÚtext_idÚthinking_idÚaudio_idÚtool_call_mappingrL   ÚchunkÚ	delta_resÚuÚptdÚ
cache_readÚchoicer¢   Ú	tool_callr¥   ÚfnÚ
delta_nameÚ
delta_argsÚ	stored_idÚstored_nameÚdelta_audioÚaudio_chunkÚ	pcm_bytesÚpayloads                                rC   r{   z)DashScopeChatModel._parse_stream_response  s´  è è € ð( #(ÐàˆÝ'™>œ>ˆÝ#‘~”~ˆÝ'™>œ>ˆÝ‘>”>ˆå"-¡-¤-Ðàð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$˜vØ%ð c$ð c$ð c$ð c$ð c$ð c$ð c$�eÝ(ØØ!Ø"ðñ ô �	õ & e¨T°4Ñ8Ô8ÐG¸K�Ø*�	”à”;ð Øœ�AÝ! !Ð%<¸dÑCÔC�CØð '�w s¨OÑ<Ô<ð 'Ø%(Ô%6Ð%;¸!˜
˜
à%&˜
Ý%Ø%&¤_Ð%9¸Ø&'Ô&9Ð&>¸QÝ&œl™nœn¨~Ñ=×LÒLÑNÔNØ+5ð	ñ ô �Eð ”}ð ØÐ(Ø*/˜	œØ'˜˜˜˜Øàœ qÔ)�Øœ�õ ˜5Ð"5°tÑ<Ô<ð Ø×-Ò-Ø!,Ø!&Ô!8ð .ñ ô ð õ ˜5 )¨TÑ2Ô2ð Ø×)Ò)Ø!(Ø"œ]ð *ñ ô ð õ ")¨°¸dÑ!CÔ!CÐ!IÀrð ð �IØ%œO�EÝ  ¨J¸Ñ=Ô=�BØ>@Ð!J¥¨¨V°TÑ!:Ô!:Ð!:Àd�JØCEÐ!O¥¨¨[¸$Ñ!?Ô!?Ð!?È4�Jð Ð$5Ð5Ð5à%œLØ&Ð3¨)ð4Ð)¨%Ñ0ð
 .?¸uÔ-EÑ*�I˜{à×.Ò.Ø!*¤Ð!:°Ø'Ð6¨;Ø(Ð.¨Bð /ñ ô ð ð õ ˜5 '¨4Ñ0Ô0ð Ý")¨%°¸$Ñ"?Ô"?�KÝ! +­tÑ4Ô4ð GØ&1§o¢o°f¸bÑ&AÔ&A˜˜å&-¨k¸6À2Ñ&FÔ&F˜à"ð Ý$*Ô$4°[Ñ$AÔ$A˜	Ø0ð 0Ý&AÑ&CÔ&CÀiÑ&O˜GØ04Ð-Ð-à&/˜Gð "×3Ò3Ø%-Ø!(Ø'2ð 4ñ ô ð ð Ô$ð $¨ð $Ø&+�I”OØ#�O�O�O�OùðG  &˜vðd	$ð d	$ð d	$ñ d	$ô d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$ð d	$øøøð d	$ð d	$ð d	$ð d	$ð d	$ð d	$s   ÁK<ÁK'ÁJ
K<Ë<
LÌ	Lc                 ó6  — g }|j         rå|j         d         }t          |j        dd¦  «        }t          |t          ¦  «        r%|r#|                     t          |¬¦  «        ¦  «         |j        j        r-|                     t          |j        j        ¬¦  «        ¦  «         |j        j	        pg D ]@}|                     t          |j        |j        j        |j        j        ¬¦  «        ¦  «         ŒAd}|j        ry|j        }t          |dd¦  «        }	|	rt!          |	d¦  «        r
|	j        pd}
nd}
t%          |j        |j        t+          j        ¦   «         |z
                       ¦   «         |
¬	¦  «        }|d
|dœ}t          |dd¦  «        }|r||d<   t1          di |¤ŽS )a¤  Parse the DashScope non-streaming response (OpenAI-compatible
        format).

        Args:
            start_datetime (`datetime`):
                The start datetime of the response generation.
            response (`ChatCompletion`):
                The OpenAI-compatible chat completion object.

        Returns:
            `ChatResponse`:
                A single ``ChatResponse`` with ``is_last=True``.
        r   r�   N)r‘   )rn   )r‡   r”   r˜   rˆ   r‰   rŠ   T)r…   r†   rœ   r‡   rA   )r¡   r›   Úmessager§   r@   Úappendr   r…   r   r’   r   r‡   r“   r”   r•   rœ   r�   r‰   r   rž   rŸ   r   rw   r    r   )r\   r�   r‚   Úcontent_blocksr¸   Ú	reasoningr¹   rœ   rµ   r¶   r·   Úresp_kwargsr®   s                rC   r|   z-DashScopeChatModel._parse_completion_response’  så  € ð$ KMˆàÔð 	ØÔ% aÔ(ˆFÝ ¤Ð0CÀTÑJÔJˆIÝ˜)¥SÑ)Ô)ð I¨ið IØ×%Ò%¥m¸YÐ&GÑ&GÔ&GÑHÔHÐHàŒ~Ô%ð NØ×%Ò%¥i°V´^Ô5KÐ&LÑ&LÔ&LÑMÔMÐMà#œ^Ô6Ð<¸"ð ð �	Ø×%Ò%Ý!Ø$œ<Ø&Ô/Ô4Ø'Ô0Ô:ðñ ô ñô ð ð ð ˆØŒ>ð 	Ø”ˆAÝ˜!Ð4°dÑ;Ô;ˆCØð •w˜s OÑ4Ô4ð Ø Ô.Ð3°!�
�
à�
ÝØœ_ØÔ1Ý”l‘n”n ~Ñ5×DÒDÑFÔFØ#-ð	ñ ô ˆEð &ØØð'
ð '
ˆõ
 ˜h¨¨dÑ3Ô3ˆØð 	,Ø +ˆK˜ÑåÐ*Ð*˜kÐ*Ð*Ð*rB   c                 ó°  ‡— |rA|r?|                       ||¦  «         |j        r"t          |j        ¦  «        Šˆfd„|D ¦   «         }d}|rB|D ]=}t          |t          ¦  «        rd|vs|d         dk    sd|vrt          d|› �¦  «        ‚Œ>|}|s|dfS |j        }|t          vr	|dd|idœfS |dk    r$t          j	        d	|› d
�t          d¬¦  «         |dfS ||fS )aâ  Validate and format tools and tool_choice for DashScope.

        DashScope supports "auto", "none", and "required" modes in
        OpenAI-compatible format. When ``tool_choice.tools`` is specified
        the schemas list is filtered to only those tools. When
        ``tool_choice.mode`` is a specific tool name (str) the model is
        forced to call exactly that tool.

        Args:
            tools (`list[dict] | None`, optional):
                The raw tool schemas.
            tool_choice (`ToolChoice | None`, optional):
                The tool choice configuration.

        Returns:
            `tuple[list[dict] | None, str | dict | None]`:
                A tuple of (formatted_tools, formatted_tool_choice).
        c                 ó4   •— g | ]}|d          d         ‰v ¯|‘ŒS )r“   r”   rA   )Ú.0ÚtÚalloweds     €rC   ú
<listcomp>z4DashScopeChatModel._format_tools.<locals>.<listcomp>í  s,   ø€ ÐNÐNÐN˜q¨Q¨z¬]¸6Ô-BÀgÐ-MÐ-M˜Ð-MÐ-MÐ-MrB   NrF   r“   zMEach schema must be a dict with 'type' as 'function' and 'function' key, got r”   )rF   r“   Úrequiredú'zJ' is not fully supported by DashScope API. It will be converted to 'auto'.r   )Ú
stacklevelÚauto)Ú_validate_tool_choicerg   Úsetr§   r¨   Ú
ValueErrorÚmoder   ÚwarningsÚwarnÚDeprecationWarning)r\   rg   rh   r   ÚvaluerÖ   rÍ   s         @rC   ru   z DashScopeChatModel._format_toolsÒ  s‡  ø€ ð. ð 	O˜5ð 	OØ×&Ò& {°EÑ:Ô:Ð:ØÔ ð OÝ˜kÔ/Ñ0Ô0�ØNÐNÐNÐN EÐNÑNÔN�àˆ	Øð 	Øð 
ð 
�å" 5­$Ñ/Ô/ð	à UÐ*Ð*Ø˜V”}¨
Ò2Ð2Ø!¨Ð.Ð.å$ðFØ>CðFð Fñô ð ð /ð ˆIàð 	#Ø˜d�?Ð"àÔˆàÕ1Ð1Ð1ØØ"Ø# T˜Nðð ð ð ð
 �:ÒÐÝŒMð2�Dð 2ð 2ð 2å"Øð	ñ ô ð ð ˜fÐ$Ð$à˜$ˆÐrB   Ústructured_modelc              ‹   óŒ   •K  — |€| j         j        rt          d¬¦  «        } t          ¦   «         j        d||||dœ|¤Žƒ d{V —†S )aæ  DashScope-specific override for structured output.

        DashScope rejects ``tool_choice="required"`` or an object-form
        ``tool_choice`` when thinking mode is enabled. In that case we
        default ``tool_choice`` to ``"auto"`` and rely on the base class's
        injected system-reminder prompt to guide the model. When thinking
        is disabled, this falls through to the base implementation.

        See: https://help.aliyun.com/en/model-studio/qwen-function-calling

        Args:
            model_name (`str`):
                The model name to use for this call.
            messages (`list[Msg]`):
                The context for the LLM to generate the structured output.
            structured_model (`Type[BaseModel] | dict`):
                A Pydantic model class or a JSON schema dict describing the
                required output structure.
            tool_choice (`ToolChoice | None`, defaults to `None`):
                The tool_choice forwarded to ``_call_api``. When ``None``
                and thinking mode is enabled, it is downgraded to
                ``ToolChoice(mode="auto")``; otherwise the base default
                (force the structured-output tool) is used.
            **kwargs (`Any`):
                Additional keyword arguments forwarded to ``_call_api``.

        Returns:
            `StructuredResponse`:
                The structured response whose ``content`` is the validated
                output dict matching ``structured_model``.
        NrÒ   )rÖ   )re   rf   rÛ   rh   rA   )rK   r*   r   rV   Ú _call_api_with_structured_output)r\   re   rf   rÛ   rh   ri   r]   s         €rC   rÝ   z3DashScopeChatModel._call_api_with_structured_output  sƒ   øè è € ðN Ð 4¤?Ô#BÐÝ$¨&Ð1Ñ1Ô1ˆKØ=•U‘W”WÔ=ð 
Ø!ØØ-Ø#ð	
ð 
ð
 ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
rB   )NTr   rG   rH   NN)NN)N)&r8   r9   r:   r;   r   rD   rF   r   r=   r   r@   r>   r<   r?   r   r¨   r   rW   ÚclassmethodÚtupler	   Ú	Exceptionrd   Úlistr   r   r   r   rƒ   r   r   r{   r   r|   ru   r   rÝ   Ú__classcell__)r]   s   @rC   r!   r!   "   s:  ø€ € € € € € ðð ðB
ð B
ð B
ð B
ð B
�Yñ B
ô B
ð B
ðH '7€Dˆ'Ð"Ô
#Ð6Ð6Ñ6Ø%ð >BØØØ Ø"Ø*.Ø/3ð9
ð 9
à'ð9
ð ð9
ð ;ð	9
ð
 ð9
ð ð9
ð ð9
ð ð9
ð ! 4Ñ'ð9
ð ˜C ˜H”~¨Ñ,ð9
ð 
ð9
ð 9
ð 9
ð 9
ð 9
ð 9
ðv ð
¨%°°Y´ÀÐ0DÔ*Eð 
ð 
ð 
ñ „[ð
ð $(Ø)-ðTIð TIàðTIð �s”)ðTIð �DŒz˜DÑ ð	TIð
   $Ñ&ðTIð ðTIð 
˜ |°TÐ'9Ô:Ñ	:ðTIð TIð TIð TIðlB$à ðB$ð ðB$ð 
˜ dÐ*Ô	+ð	B$ð B$ð B$ð B$ðH>+à ð>+ð !ð>+ð 
ð	>+ð >+ð >+ð >+ð@@à�DŒz˜DÑ ð@ð   $Ñ&ð@ð 
ˆt�DŒz˜DÑ  #¨¡*¨tÑ"3Ð3Ô	4ð	@ð @ð @ð @ðN *.ð/
ð /
àð/
ð �s”)ð/
ð ˜yœ/¨DÑ0ð	/
ð
   $Ñ&ð/
ð ð/
ð 
ð/
ð /
ð /
ð /
ð /
ð /
ð /
ð /
ð /
ð /
rB   r!   )-r;   rª   r×   Úcollectionsr   r   Útypingr   r   r   r   r	   r
   Úpydanticr   r   Ú_utils._audior   Ú_utils._commonr   Ú_baser   r   Ú_model_responser   r   Ú_model_usager   rI   r   rP   r   r   rÄ   r   r   r   r   Útoolr   Úopenai.types.chatr   rX   r   r!   rA   rB   rC   ú<module>rí      sà  ðà HÐ HØ €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jà %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø *Ð *Ð *Ð *Ð *Ð *Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø $Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >ðð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð àð Ø0Ð0Ð0Ð0Ð0Ð0Ø"Ð"Ð"Ð"Ð"Ð"Ð"à€NØ€Kða
ð a
ð a
ð a
ð a
˜ñ a
ô a
ð a
ð a
ð a
rB   