Ë
    ´ŒjD$  ã                   óT   — d Z ddlZddlmZ ddlmZ dZ	 ddededefd	„Zdedefd
„Z	y)aý  
This module converts between AIMessage output formats for the Responses API.

ChatOpenAI v0.3 stores reasoning and tool outputs in AIMessage.additional_kwargs:

.. code-block:: python

    AIMessage(
        content=[
            {"type": "text", "text": "Hello, world!", "annotations": [{"type": "foo"}]}
        ],
        additional_kwargs={
            "reasoning": {
                "type": "reasoning",
                "id": "rs_123",
                "summary": [{"type": "summary_text", "text": "Reasoning summary"}],
            },
            "tool_outputs": [
                {
                    "type": "web_search_call",
                    "id": "websearch_123",
                    "status": "completed",
                }
            ],
            "refusal": "I cannot assist with that.",
        },
        response_metadata={"id": "resp_123"},
        id="msg_123",
    )

To retain information about response item sequencing (and to accommodate multiple
reasoning items), ChatOpenAI now stores these items in the content sequence:

.. code-block:: python

    AIMessage(
        content=[
            {
                "type": "reasoning",
                "summary": [{"type": "summary_text", "text": "Reasoning summary"}],
                "id": "rs_123",
            },
            {
                "type": "text",
                "text": "Hello, world!",
                "annotations": [{"type": "foo"}],
                "id": "msg_123",
            },
            {"type": "refusal", "refusal": "I cannot assist with that."},
            {"type": "web_search_call", "id": "websearch_123", "status": "completed"},
        ],
        response_metadata={"id": "resp_123"},
        id="resp_123",
    )

There are other, small improvements as well-- e.g., we store message IDs on text
content blocks, rather than on the AIMessage.id, which now stores the response ID.

For backwards compatibility, this module provides functions to convert between the
old and new formats. The functions are used internally by ChatOpenAI.

é    N)ÚUnion)Ú	AIMessageÚ__openai_function_call_ids__ÚmessageÚhas_reasoningÚreturnc           	      ó˜  — t        | j                  t        «      �r§g }| j                  D �]P  }t        |t        «      �r+|j	                  d«      dk(  rH|j                  dd«      }|r$|j                  dd«      }|j                  dd«      }|| j                  d<   Œq|j	                  d«      dv r<d| j                  vrg | j                  d<   | j                  d   j                  |«       ŒÀ|j	                  d«      dk(  rgt        | j                  vri | j                  t        <   |j	                  d	«      x}s�Œ|j	                  d«      x}s�Œ#|| j                  t           |<   �Œ;|j	                  d«      d
k(  r$|j	                  d
«      x}r|| j                  d
<   �Œs|j	                  d«      dk(  rId|v r
|d   | _	        |j                  |j                  «       D ��	ci c]  \  }}	|dk7  sŒ||	“Œ c}	}«       �ŒÐt        |j                  «       «      ddhk(  r?t        |d   t        «      r,|d   j                  d«      r|j                  d|d   i«       �Œ-|j                  |«       �Œ@|j                  |«       �ŒS || _        t        | j                  t        «      r"| j                  j                  d«      rd| _	        | S 	 | S c c}	}w )z1Mutate an AIMessage to the old-style v0.3 format.ÚtypeÚ	reasoningÚindexNÚid)Úweb_search_callÚfile_search_callÚcomputer_callÚcode_interpreter_callÚmcp_callÚmcp_list_toolsÚmcp_approval_requestÚimage_generation_callÚtool_outputsÚfunction_callÚcall_idÚrefusalÚtextÚmsg_Úresp_)Ú
isinstanceÚcontentÚlistÚdictÚgetÚpopÚadditional_kwargsÚappendÚ_FUNCTION_CALL_IDS_MAP_KEYr   ÚitemsÚsetÚkeysÚstrÚ
startswith)
r   r   Únew_contentÚblockÚ_r   Úfunction_call_idr   ÚkÚvs
             ún/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_openai/chat_models/_compat.pyÚ_convert_to_v03_ai_messager2   H   sŽ  € ô �'—/‘/¤4Õ(Ø.0ˆØ—_•_ˆEÜ˜%¤Õ&Ø—9‘9˜VÓ$¨Ò3ð Ÿ	™	 '¨4Ó0�AÙ$Ø!ŸI™I d¨DÓ1˜Ø!ŸI™I f¨dÓ3˜Ø=B�G×-Ñ-¨kÒ:Ø—Y‘Y˜vÓ&ð 	+ñ 	ð &¨W×-FÑ-FÑFØDF˜×1Ñ1°.ÑAØ×-Ñ-¨nÑ=×DÑDÀUÕKØ—Y‘Y˜vÓ&¨/Ò9ô 2¸×9RÑ9RÑRØPR˜×1Ñ1Ô2LÑMØ#(§9¡9¨YÓ#7Ð7˜Ò7Ø,1¯I©I°d«OÐ;Ð(Ò;ð -ð  ×1Ñ1Ô2LÑMØ#óð —i‘i Ó'¨9Ò4Ø$Ÿy™y¨Ó3Ð3�GÐ3ð <C�G×-Ñ-¨iÓ8Ø—Y‘Y˜vÓ&¨&Ò0à˜u‘}Ø%*¨4¡[˜œ
Ø×&Ñ&¸¿¹¼Ô'T¹±°°AÈ!ÈtË)¨¨1©¸Ò'TÖUä˜Ÿ
™
›Ó%¨$°¨Ò8Ü" 5¨¡;´Ô4Ø˜d™×.Ñ.¨vÔ6ð  ×&Ñ&¨°°w±Ð'@ÖAà×&Ñ& uÖ-à×"Ñ" 5Ö)ðq %ðr &ˆŒÜ�g—j‘j¤#Ô&¨7¯:©:×+@Ñ+@ÀÔ+IØˆGŒJð €Nð 	à€Nùó% (Us   ÇKÇ+Kc                 óp  ‡ — t        ‰ j                  t        «      xr t        d„ ‰ j                  D «       «      xr™ t	        ˆ fd„dddt
        fD «       «      xs{ t        ‰ j                  t        «      xr_ ‰ j                  j                  d«      xrB ‰ j                  j                  d«      x}xr# t        |t        «      xr |j                  d«      }|s‰ S g d	¢}|D �ci c]  }|g “Œ }}g }‰ j                  j                  d«      x}r|d   j                  |«       ‰ j                  j                  d«      x}r|d   j                  d|d
œ«       ‰ j                  D ]   }	t        |	t        «      r}|	j                  d«      dk(  ri|	j                  «       }
t        ‰ j                  t        «      r*‰ j                  j                  d«      r‰ j                  |
d<   |d   j                  |
«       Œ�|j                  |	«       Œ¢ ‰ j                  j                  t
        «      }‰ j                  D ]X  }d|d   t!        j"                  |d   d¬«      |d   dœ}|�|j                  |d   «      x}r||d<   |d   j                  |«       ŒZ ‰ j                  j                  dg «      }|D ]O  }	t        |	t        «      r,|	j                  d«      x}r||v r||   j                  |	«       Œ?|j                  |	«       ŒQ g }|D ]  }|j%                  ||   «       Œ |j%                  |«       t        ‰ j                  «      }|j'                  dd«       |j'                  dd«       |j'                  dd«       d‰ j                  v r‰ j                  d   }n‰ j                  }‰ j)                  |||dœd¬«      S c c}w )zFConvert an old-style v0.3 AIMessage into the new content-block format.c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­w©N)r   r    )Ú.0Úbs     r1   Ú	<genexpr>z/_convert_from_v03_ai_message.<locals>.<genexpr>–   s   è ø€ Ð=©_¨”
˜1œd×#©_ùs   ‚c              3   ó:   •K  — | ]  }|‰j                   v –— Œ y ­wr5   )r#   )r6   Úitemr   s     €r1   r8   z/_convert_from_v03_ai_message.<locals>.<genexpr>˜   s(   øè ø€ ð 
ñ�ð �G×-Ñ-Ô-ñùs   ƒr   r   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   )r
   r   r
   r   r   ÚnameÚargsF)Úensure_ascii)r
   r;   Ú	argumentsr   N)r   r#   r   )ÚupdateÚdeep)r   r   r   ÚallÚanyr%   r   r)   r*   Úresponse_metadatar!   r#   r$   r    ÚcopyÚ
tool_callsÚjsonÚdumpsÚextendr"   Ú
model_copy)r   Úresponse_idÚis_chatopenai_v03Úcontent_orderÚkeyÚbucketsÚunknown_blocksr   r   r,   Ú
block_copyÚfunction_call_idsÚ	tool_callr   Ú_idr   r+   Únew_additional_kwargsÚnew_ids   `                  r1   Ú_convert_from_v03_ai_messagerV   �   s¬  ø€ ô
 	�7—?‘?¤DÓ)ò 	>ÜÑ=¨W¯_ª_Ó=Ó=òô 	ó 
ð ØØÜ*ñ	ó
ó 	
ò 	
ô �w—z‘z¤3Ó'ò 0Ø—
‘
×%Ñ% fÓ-ò0à '× 9Ñ 9× =Ñ =¸dÓ CÐC�ò0ô ˜;¬Ó,ò0ð ×&Ñ& wÓ/ð% ñ* Øˆò€Mñ  4AÓA±=¨C  R¡°=€GÐAØ€Nð ×-Ñ-×1Ñ1°+Ó>Ð>€yÐ>Ø�Ñ×#Ñ# IÔ.ð ×+Ñ+×/Ñ/°	Ó:Ð:€wÐ:Ø�	Ñ×!Ñ!¨9ÀÑ"IÔJð —”ˆÜ�eœTÔ" u§y¡y°Ó'8¸FÒ'BØŸ™›ˆJÜ˜'Ÿ*™*¤cÔ*¨w¯z©z×/DÑ/DÀVÔ/LØ#*§:¡:�
˜4Ñ Ø�F‰O×"Ñ" :Õ.à×!Ñ! %Õ(ð !ð  ×1Ñ1×5Ñ5Ô6PÓQÐØ×'Ô'ˆ	à#Ø˜fÑ%ÜŸ™ I¨fÑ$5ÀEÔJØ  ‘ñ	
ˆð Ð(Ø$×(Ñ(¨°4©Ó9Ð9ˆCÐ9à"%ˆM˜$ÑØ�Ñ ×'Ñ'¨Õ6ð (ð ×,Ñ,×0Ñ0°ÀÓD€LÛˆÜ�eœTÔ"¨u¯y©y¸Ó/@Ð(@¨Ð(@ÀcÈWÁnØ�C‰L×Ñ Õ&à×!Ñ! %Õ(ð	 ð €KÛˆØ×Ñ˜7 3™<Õ(ð à×Ñ�~Ô&ä  ×!:Ñ!:Ó;ÐØ×Ñ˜k¨4Ô0Ø×Ñ˜i¨Ô.Ø×Ñ˜n¨dÔ3àˆw×(Ñ(Ñ(Ø×*Ñ*¨4Ñ0‰à—‘ˆà×Ñà"Ø!6Øñ
ð
 ð ó ð ùòy  Bs   Ã!
N3)F)
Ú__doc__rF   Útypingr   Úlangchain_core.messagesr   r%   Úboolr2   rV   © ó    r1   Ú<module>r]      sY   ðñ=ó~ Ý å -à;Ð ð /4ñEØðEØ'+ðEàóEðPo¨)ð o¸	ô or\   