§
    šŠtjdv  ã                   óZ  — d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ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mZmZ dd	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZA  ejB        eC¦  «        ZDede	deEdeEde	def
d„¦   «         ZFede	deEdeEde	de
f
d„¦   «         ZGdedeeEe	f         fd„ZHdeeEe	f         defd„ZIdeeEe	f         dee          de fd„ZJ G d „ d!e¦  «        ZKdS )"z#Wrapper around Minimax chat models.é    N)ÚasynccontextmanagerÚcontextmanager)Ú
itemgetter)
ÚAnyÚAsyncIteratorÚCallableÚDictÚIteratorÚListÚOptionalÚSequenceÚTypeÚUnion)ÚAsyncCallbackManagerForLLMRunÚCallbackManagerForLLMRun)ÚLanguageModelInput)ÚBaseChatModelÚagenerate_from_streamÚgenerate_from_stream)	Ú	AIMessageÚAIMessageChunkÚBaseMessageÚBaseMessageChunkÚChatMessageÚChatMessageChunkÚHumanMessageÚSystemMessageÚToolMessage)ÚOutputParserLike)ÚJsonOutputKeyToolsParserÚPydanticToolsParser)ÚChatGenerationÚChatGenerationChunkÚ
ChatResult)ÚRunnableÚRunnableMapÚRunnablePassthrough)ÚBaseTool)Úconvert_to_secret_strÚget_from_dict_or_env©Úconvert_to_openai_tool)Ú
get_fields)Ú	BaseModelÚ
ConfigDictÚFieldÚ	SecretStrÚmodel_validatorÚclientÚmethodÚurlÚkwargsÚreturnc              +   ó€   K  — ddl m}  | j        ||fi |¤Ž5 } ||¦  «        V — ddd¦  «         dS # 1 swxY w Y   dS )a  Context manager for connecting to an SSE stream.

    Args:
        client: The httpx client.
        method: The HTTP method.
        url: The URL to connect to.
        kwargs: Additional keyword arguments to pass to the client.

    Yields:
        An EventSource object.
    r   ©ÚEventSourceN©Ú	httpx_sser:   Ústream©r3   r4   r5   r6   r:   Úresponses         úe/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/chat_models/minimax.pyÚconnect_httpx_sserA   ?   s­   è è € ð &Ð%Ð%Ð%Ð%Ð%à	ˆŒ�v˜sÐ	-Ð	- fÐ	-Ð	-ð $°Øˆk˜(Ñ#Ô#Ð#Ð#Ð#ð$ð $ð $ñ $ô $ð $ð $ð $ð $ð $ð $ð $øøøð $ð $ð $ð $ð $ð $s   ˜3³7º7c                ó¦   K  — ddl m}  | j        ||fi |¤Ž4 ƒd{V —†} ||¦  «        W V — ddd¦  «        ƒd{V —† dS # 1 ƒd{V —†swxY w Y   dS )a  Async context manager for connecting to an SSE stream.

    Args:
        client: The httpx client.
        method: The HTTP method.
        url: The URL to connect to.
        kwargs: Additional keyword arguments to pass to the client.

    Yields:
        An EventSource object.
    r   r9   Nr;   r>   s         r@   Úaconnect_httpx_sserC   R   s
  è è € ð &Ð%Ð%Ð%Ð%Ð%àˆvŒ}˜V SÐ3Ð3¨FÐ3Ð3ð $ð $ð $ð $ð $ð $ð $°xØˆk˜(Ñ#Ô#Ð#Ð#Ð#Ð#ð$ð $ð $ñ $ô $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $ð $øøøð $ð $ð $ð $ð $ð $s   žA Á 
A
ÁA
Úmessagec                 ó¾  — t          | t          ¦  «        rd| j        dœ}n¼t          | t          ¦  «        r$d| j        | j                             d¦  «        dœ}nƒt          | t          ¦  «        rd| j        dœ}nct          | t          ¦  «        r1d| j        | j        | j	        p| j                             d¦  «        d	œ}nt          d
| j        j        › d�¦  «        ‚|S )z%Convert a LangChain messages to Dict.Úuser©ÚroleÚcontentÚ	assistantÚ
tool_calls)rH   rI   rK   ÚsystemÚtoolÚname)rH   rI   Útool_call_idrN   zGot unknown type 'z'.)Ú
isinstancer   rI   r   Úadditional_kwargsÚgetr   r   rO   rN   Ú	TypeErrorÚ	__class__Ú__name__)rD   Úmessage_dicts     r@   Ú_convert_message_to_dictrW   g   sý   € õ �'�<Ñ(Ô(ð MØ &°7´?ÐCÐCˆˆÝ	�G�YÑ	'Ô	'ð MàØ”Ø!Ô3×7Ò7¸ÑEÔEð
ð 
ˆˆõ
 
�G�]Ñ	+Ô	+ð 
MØ (°W´_ÐEÐEˆˆÝ	�G�[Ñ	)Ô	)ð MàØ”Ø#Ô0Ø”LÐI GÔ$=×$AÒ$AÀ&Ñ$IÔ$Ið	
ð 
ˆˆõ ÐK¨WÔ->Ô-GÐKÐKÐKÑLÔLÐLØÐó    Údctc                 óæ   — |                       d¦  «        }|                       dd¦  «        }|dk    r0i }|                       dd¦  «        }|�||d<   t          ||¬¦  «        S t          ||¬¦  «        S )	z$Convert a dict to LangChain message.rH   rI   Ú rJ   rK   N©rI   rQ   rG   )rR   r   r   )rY   rH   rI   rQ   rK   s        r@   Ú_convert_dict_to_messager]   €   s€   € à�7Š7�6‰?Œ?€DØ�gŠg�i Ñ$Ô$€GØˆ{ÒÐØÐØ—W’W˜\¨4Ñ0Ô0ˆ
ØÐ!Ø.8Ð˜lÑ+Ý Ð<MÐNÑNÔNÐNÝ˜D¨'Ð2Ñ2Ô2Ð2rX   Údefault_classc                 ó.  — |                       d¦  «        }|                       dd¦  «        }i }|                       dd ¦  «        }|�||d<   |dk    s|t          k    rt          ||¬¦  «        S |s|t          k    rt          ||¬¦  «        S  ||¬	¦  «        S )
NrH   rI   r[   Ú	tool_callrK   rJ   r\   )rI   rH   )rI   )rR   r   r   )rY   r^   rH   rI   rQ   rK   s         r@   Ú_convert_delta_to_message_chunkra   �   s²   € ð �7Š7�6‰?Œ?€DØ�gŠg�i Ñ$Ô$€GØÐØ—’˜ dÑ+Ô+€JØÐØ*4Ð˜,Ñ'àˆ{ÒÐ˜m­~Ò=Ð=Ý gÐARÐSÑSÔSÐSØð <ˆ}Õ 0Ò0Ð0Ý¨°dÐ;Ñ;Ô;Ð;Øˆ= Ð)Ñ)Ô)Ð)rX   c                   óÀ  ‡ — e Zd ZU dZedeeef         fd„¦   «         Zedefd„¦   «         Z	edeeef         fd„¦   «         Z
dZeed<   dZeed	<   	 d
Zeed<   	 dZeed<   	 dZeed<   	  ee¬¦  «        Zeeef         ed<   	  edd¬¦  «        Zeed<    edd¬¦  «        Zee         ed<   	  ed¬¦  «        Zeed<   	 dZeed<   	  ed¬¦  «        Z ed¬ ¦  «        e d!edefd"„¦   «         ¦   «         Z!d#e"ee#f         de$fd$„Z%	 d8d%e&e'         d&ed'edeeef         fd(„Z(e)d)eeef         ddfd*„¦   «         Z*	 	 	 d9d%e&e'         d+ee&e                  d,ee+         d-ee         d'ede$fd.„Z,	 	 d:d%e&e'         d+ee&e                  d,ee+         d'ede-e.         f
d/„Z/	 	 	 d9d%e&e'         d+ee&e                  d,ee0         d-ee         d'ede$fd0„Z1	 	 d:d%e&e'         d+ee&e                  d,ee0         d'ede2e.         f
d1„Z3d2e4e"eeef         e5e#         e6e7f                  d'ede8e9e:f         fˆ fd3„Z;dd4œd5e"ee5e#         f         d6ed'ede8e9e"ee#f         f         fd7„Z<ˆ xZ=S );ÚMiniMaxChatu  MiniMax chat model integration.

    Setup:
        To use, you should have the environment variable``MINIMAX_API_KEY`` set with
    your API KEY.

        .. code-block:: bash

            export MINIMAX_API_KEY="your-api-key"

    Key init args â€” completion params:
        model: Optional[str]
            Name of MiniMax model to use.
        max_tokens: Optional[int]
            Max number of tokens to generate.
        temperature: Optional[float]
            Sampling temperature.
        top_p: Optional[float]
            Total probability mass of tokens to consider at each step.
        streaming: Optional[bool]
             Whether to stream the results or not.

    Key init args â€” client params:
        api_key: Optional[str]
            MiniMax API key. If not passed in will be read from env var MINIMAX_API_KEY.
        base_url: Optional[str]
            Base URL for API requests.

    See full list of supported init args and their descriptions in the params section.

    Instantiate:
        .. code-block:: python

            from langchain_community.chat_models import MiniMaxChat

            chat = MiniMaxChat(
                api_key=api_key,
                model='abab6.5-chat',
                # temperature=...,
                # other params...
            )

    Invoke:
        .. code-block:: python

            messages = [
                ("system", "ä½ æ˜¯ä¸€å��ä¸“ä¸šçš„ç¿»è¯‘å®¶ï¼Œå�¯ä»¥å°†ç”¨æˆ·çš„ä¸­æ–‡ç¿»è¯‘ä¸ºè‹±æ–‡ã€‚"),
                ("human", "æˆ‘å–œæ¬¢ç¼–ç¨‹ã€‚"),
            ]
            chat.invoke(messages)

        .. code-block:: python

            AIMessage(
                content='I enjoy programming.',
                response_metadata={
                    'token_usage': {'total_tokens': 48},
                    'model_name': 'abab6.5-chat',
                    'finish_reason': 'stop'
                },
                id='run-42d62ba6-5dc1-4e16-98dc-f72708a4162d-0'
            )

    Stream:
        .. code-block:: python

            for chunk in chat.stream(messages):
                print(chunk)

        .. code-block:: python

            content='I' id='run-a5837c45-4aaa-4f64-9ab4-2679bbd55522'
            content=' enjoy programming.' response_metadata={'finish_reason': 'stop'} id='run-a5837c45-4aaa-4f64-9ab4-2679bbd55522'

        .. code-block:: python

            stream = chat.stream(messages)
            full = next(stream)
            for chunk in stream:
                full += chunk
            full

        .. code-block:: python

            AIMessageChunk(
                content='I enjoy programming.',
                response_metadata={'finish_reason': 'stop'},
                id='run-01aed0a0-61c4-4709-be22-c6d8b17155d6'
            )

    Async:
        .. code-block:: python

            await chat.ainvoke(messages)

            # stream
            # async for chunk in chat.astream(messages):
            #     print(chunk)

            # batch
            # await chat.abatch([messages])

        .. code-block:: python

            AIMessage(
                content='I enjoy programming.',
                response_metadata={
                    'token_usage': {'total_tokens': 48},
                    'model_name': 'abab6.5-chat',
                    'finish_reason': 'stop'
                },
                id='run-c263b6f1-1736-4ece-a895-055c26b3436f-0'
            )

    Tool calling:
        .. code-block:: python

            from pydantic import BaseModel, Field


            class GetWeather(BaseModel):
                '''Get the current weather in a given location'''

                location: str = Field(
                    ..., description="The city and state, e.g. San Francisco, CA"
                )


            class GetPopulation(BaseModel):
                '''Get the current population in a given location'''

                location: str = Field(
                    ..., description="The city and state, e.g. San Francisco, CA"
                )

            chat_with_tools = chat.bind_tools([GetWeather, GetPopulation])
            ai_msg = chat_with_tools.invoke(
                "Which city is hotter today and which is bigger: LA or NY?"
            )
            ai_msg.tool_calls

        .. code-block:: python

            [
                {
                    'name': 'GetWeather',
                    'args': {'location': 'LA'},
                    'id': 'call_function_2140449382',
                    'type': 'tool_call'
                }
            ]

    Structured output:
        .. code-block:: python

            from typing import Optional

            from pydantic import BaseModel, Field


            class Joke(BaseModel):
                '''Joke to tell user.'''
                setup: str = Field(description="The setup of the joke")
                punchline: str = Field(description="The punchline to the joke")
                rating: Optional[int] = Field(description="How funny the joke is, from 1 to 10")


            structured_chat = chat.with_structured_output(Joke)
            structured_chat.invoke("Tell me a joke about cats")

        .. code-block:: python

            Joke(
                setup='Why do cats have nine lives?',
                punchline='Because they are so cute and cuddly!',
                rating=None
            )

    Response metadata
        .. code-block:: python

            ai_msg = chat.invoke(messages)
            ai_msg.response_metadata

        .. code-block:: python

            {'token_usage': {'total_tokens': 48},
             'model_name': 'abab6.5-chat',
             'finish_reason': 'stop'}

    r7   c                 ó&   — i d| j         i¥| j        ¥S )zGet the identifying parameters.Úmodel)re   Ú_default_params©Úselfs    r@   Ú_identifying_paramszMiniMaxChat._identifying_params_  s   € ð A�7˜DœJÐ'Ð@¨4Ô+?Ð@Ð@rX   c                 ó   — dS )zReturn type of llm.Úminimax© rg   s    r@   Ú	_llm_typezMiniMaxChat._llm_typed  s	   € ð ˆyrX   c                 óF   — | j         | j        | j        | j        dœ| j        ¥S )z2Get the default parameters for calling OpenAI API.)re   Ú
max_tokensÚtemperatureÚtop_p)re   ro   rp   rq   Úmodel_kwargsrg   s    r@   rf   zMiniMaxChat._default_paramsi  s5   € ð ”ZØœ/ØÔ+Ø”Zð	
ð 
ð
 Ôð
ð 	
rX   NÚ_clientzabab6.5s-chatre   é   ro   gffffffæ?rp   gffffffî?rq   )Údefault_factoryrr   z3https://api.minimaxi.chat/v1/text/chatcompletion_v2Úbase_url)ÚdefaultÚaliasÚminimax_api_hostÚgroup_idÚminimax_group_idÚapi_key)rx   Úminimax_api_keyFÚ	streamingT)Úpopulate_by_nameÚbefore)ÚmodeÚvaluesc                 ó  — t          t          |ddgd¦  «        ¦  «        |d<   d„ t          | ¦  «                             ¦   «         D ¦   «         }|                     |¦  «         t          |ddgd|d         ¦  «        |d<   |S )z?Validate that api key and python package exists in environment.r}   r|   ÚMINIMAX_API_KEYc                 ó2   — i | ]\  }}|j         ®||j         “ŒS ©N)rw   )Ú.0rN   Úfields      r@   ú
<dictcomp>z4MiniMaxChat.validate_environment.<locals>.<dictcomp>™  s2   € ð 
ð 
ð 
á��eØŒ}Ð(ð �%”-à(Ð(Ð(rX   ry   rv   ÚMINIMAX_API_HOST)r)   r*   r-   ÚitemsÚupdate)Úclsr‚   Údefault_valuess      r@   Úvalidate_environmentz MiniMaxChat.validate_environment�  s¯   € õ %:Ý ØØ" IÐ.Ø!ñô ñ%
ô %
ˆÐ Ñ!ð
ð 
å)¨#™œ×4Ò4Ñ6Ô6ð
ñ 
ô 
ˆð
 	×Ò˜fÑ%Ô%Ð%õ &:ØØ Ð,ØØÐ-Ô.ñ	&
ô &
ˆÐ!Ñ"ð ˆrX   r?   c                 óˆ  — g }t          |t          ¦  «        s|                     ¦   «         }|d         D ]^}t          |d         ¦  «        }t          |                     d¦  «        ¬¦  «        }|                     t          ||¬¦  «        ¦  «         Œ_|                     di ¦  «        }|| j        dœ}t          ||¬¦  «        S )	NÚchoicesrD   Úfinish_reason)r’   ©rD   Úgeneration_infoÚusage)Útoken_usageÚ
model_name)ÚgenerationsÚ
llm_output)rP   Údictr]   rR   Úappendr"   re   r$   )rh   r?   r˜   ÚresrD   r”   r–   r™   s           r@   Ú_create_chat_resultzMiniMaxChat._create_chat_result©  sÒ   € ØˆÝ˜(¥DÑ)Ô)ð 	'Ø—}’}‘”ˆHØ˜IÔ&ð 	ð 	ˆCÝ.¨s°9¬~Ñ>Ô>ˆGÝ"°·²¸Ñ1IÔ1IÐJÑJÔJˆOØ×ÒÝ wÀÐPÑPÔPñô ð ð ð —l’l 7¨BÑ/Ô/ˆà&Øœ*ð
ð 
ˆ
õ  k¸jÐIÑIÔIÐIrX   ÚmessagesÚ	is_streamr6   c                 ó°   — d„ |D ¦   «         }| j         }||d<   |                      |                     di ¦  «        ¦  «          |j        di |¤Ž |rd|d<   |S )z#Create API request body parameters.c                 ó,   — g | ]}t          |¦  «        ‘ŒS rl   )rW   )r‡   Úms     r@   ú
<listcomp>z:MiniMaxChat._create_payload_parameters.<locals>.<listcomp>¾  s!   € ÐGÐGÐG¸Õ1°!Ñ4Ô4ÐGÐGÐGrX   rž   ÚtoolsTr=   rl   )rf   Ú_reformat_function_parametersrR   rŒ   )rh   rž   rŸ   r6   Úmessage_dictsÚpayloads         r@   Ú_create_payload_parametersz&MiniMaxChat._create_payload_parametersº  s{   € ð HÐG¸hÐGÑGÔGˆØÔ&ˆØ+ˆ�
Ñà×*Ò*¨6¯:ª:°g¸rÑ+BÔ+BÑCÔCÐCØˆŒÐ Ð ˜Ð Ð Ð àð 	%Ø $ˆG�HÑàˆrX   Ú	tools_argc                 ó¼   — | D ]X}|d         dk    rJt          |d         d         t          ¦  «        s)t          j        |d         d         ¦  «        |d         d<   ŒYdS )z,Reformat the function parameters to strings.ÚtypeÚfunctionÚ
parametersN)rP   ÚstrÚjsonÚdumps)r©   Útool_args     r@   r¥   z)MiniMaxChat._reformat_function_parametersÊ  sv   € ð "ð 	ð 	ˆHØ˜Ô :Ò-Ð-µjØ˜Ô$ \Ô2µCñ7ô 7Ð-õ 6:´ZØ˜ZÔ(¨Ô6ñ6ô 6�˜Ô$ \Ñ2øð		ð 	rX   ÚstopÚrun_managerr=   c                 óˆ  — |st          d¦  «        ‚|�|n| j        }|r  | j        |f||dœ|¤Ž}t          |¦  «        S  | j        |fi |¤Ž}d}	| j        �| j                             ¦   «         }	d|	› �ddœ}
ddl}|                     |
d	¬
¦  «        5 }| 	                    | j
        |¬¦  «        }|                     ¦   «          ddd¦  «         n# 1 swxY w Y   |                     ¦   «         }d|v r+d|d         v r!|d         d         dk    rt          d¦  «        ‚|                      |                     ¦   «         ¦  «        S )a<  Generate next turn in the conversation.
        Args:
            messages: The history of the conversation as a list of messages. Code chat
                does not support context.
            stop: The list of stop words (optional).
            run_manager: The CallbackManager for LLM run, it's not used at the moment.
            stream: Whether to stream the results or not.

        Returns:
            The ChatResult that contains outputs generated by the model.

        Raises:
            ValueError: if the last message in the list is not from human.
        ú:You should provide at least one message to start the chat!N©r²   r³   r[   úBearer úapplication/json©ÚAuthorizationzContent-Typer   é<   ©ÚheadersÚtimeout©r¯   Ú	base_respÚ
status_msgzinvalid api keyzInvalid API Key Provided)Ú
ValueErrorr~   Ú_streamr   r¨   r}   Úget_secret_valueÚhttpxÚClientÚpostry   Úraise_for_statusr¯   Ú	Exceptionr�   )rh   rž   r²   r³   r=   r6   rŸ   Ústream_iterr§   r|   r½   rÅ   r3   r?   Úfinal_responses                  r@   Ú	_generatezMiniMaxChat._generateÕ  sÖ  € ð, ð 	ÝØLñô ð ð %Ð0�F�F°d´nˆ	Øð 	5Ø&˜$œ,ØðØ#°ðð Ø@Fðð ˆKõ (¨Ñ4Ô4Ð4Ø1�$Ô1°(ÐEÐE¸fÐEÐEˆØˆØÔÐ+ØÔ*×;Ò;Ñ=Ô=ˆGà0 wÐ0Ð0Ø.ð
ð 
ˆð 	ˆˆˆà�\Š\ '°2ˆ\Ñ6Ô6ð 	(¸&Ø—{’{ 4Ô#8¸w�{ÑGÔGˆHØ×%Ò%Ñ'Ô'Ð'ð	(ð 	(ð 	(ñ 	(ô 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(øøøð 	(ð 	(ð 	(ð 	(ð "Ÿš™œˆà˜>Ð)Ð)Ø ¨{Ô ;Ð;Ð;Ø˜{Ô+¨LÔ9Ð=NÒNÐNåÐ6Ñ7Ô7Ð7Ø×'Ò'¨¯ª©¬Ñ8Ô8Ð8s   Â1CÃCÃCc              +   óÖ  K  —  | j         |fddi|¤Ž}d}| j        �| j                             ¦   «         }d|› �ddœ}ddl}|                     |d	¬
¦  «        5 }	t          |	d| j        |¬¦  «        5 }
|
                     ¦   «         D ]³}t          j	        |j
        ¦  «        }t          |d         ¦  «        dk    rŒ5|d         d         }t          |d         t          ¦  «        }|                     dd¦  «        }|�d|ind}t          ||¬¦  «        }|r|                     |j        |¬¦  «         |V — |� nŒ´ddd¦  «         n# 1 swxY w Y   ddd¦  «         dS # 1 swxY w Y   dS )z#Stream the chat response in chunks.rŸ   Tr[   Nr·   r¸   r¹   r   r»   r¼   ÚPOSTr¿   r‘   Údeltar’   r“   ©Úchunk)r¨   r}   rÄ   rÅ   rÆ   rA   ry   Úiter_sser¯   ÚloadsÚdataÚlenra   r   rR   r#   Úon_llm_new_tokenÚtext©rh   rž   r²   r³   r6   r§   r|   r½   rÅ   r3   Úevent_sourceÚsserÑ   Úchoicer’   r”   s                   r@   rÃ   zMiniMaxChat._stream  sS  è è € ð 2�$Ô1°(ÐUÐUÀdÐUÈfÐUÐUˆØˆØÔÐ+ØÔ*×;Ò;Ñ=Ô=ˆGà0 wÐ0Ð0Ø.ð
ð 
ˆð 	ˆˆˆà�\Š\ '°2ˆ\Ñ6Ô6ð 	¸&Ý"Ø˜ Ô 5¸Gðñ ô ð àØ'×0Ò0Ñ2Ô2ð ð �CÝ œJ s¤xÑ0Ô0�EÝ˜5 Ô+Ñ,Ô,°Ò1Ð1Ø Ø" 9Ô-¨aÔ0�FÝ;Ø˜wœ­ñô �Eð %+§J¢J¨ÀÑ$EÔ$E�Mð )Ð4ð )¨-Ð8Ð8à!ð $õ
 0Ø %°ðñ ô �Eð #ð NØ#×4Ò4°U´ZÀuÐ4ÑMÔMÐMØ�K�K�Kà$Ð0Ø˜ð 1ð3ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s7   ÁEÁ1C	EÄ:EÅE
	Å
EÅE
	ÅEÅE"Å%E"c              ‹   óB  K  — |st          d¦  «        ‚|�|n| j        }|r& | j        |f||dœ|¤Ž}t          |¦  «        ƒ d {V —†S  | j        |fi |¤Ž}d}	| j        �| j                             ¦   «         }	d|	› �ddœ}
dd l}|                     |
d¬	¦  «        4 ƒd {V —†}| 	                    | j
        |¬
¦  «        ƒ d {V —†}|                     ¦   «          d d d ¦  «        ƒd {V —† n# 1 ƒd {V —†swxY w Y   |                      |                     ¦   «         ¦  «        S )Nrµ   r¶   r[   r·   r¸   r¹   r   r»   r¼   r¿   )rÂ   r~   Ú_astreamr   r¨   r}   rÄ   rÅ   ÚAsyncClientrÇ   ry   rÈ   r�   r¯   )rh   rž   r²   r³   r=   r6   rŸ   rÊ   r§   r|   r½   rÅ   r3   r?   s                 r@   Ú
_ageneratezMiniMaxChat._agenerate:  s  è è € ð ð 	ÝØLñô ð ð %Ð0�F�F°d´nˆ	Øð 	<Ø'˜$œ-ØðØ#°ðð Ø@Fðð ˆKõ /¨{Ñ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;Ð;Ø1�$Ô1°(ÐEÐE¸fÐEÐEˆØˆØÔÐ+ØÔ*×;Ò;Ñ=Ô=ˆGà0 wÐ0Ð0Ø.ð
ð 
ˆð 	ˆˆˆà×$Ò$¨W¸bÐ$ÑAÔAð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ÀVØ#Ÿ[š[¨Ô)>ÀW˜[ÑMÔMÐMÐMÐMÐMÐMÐMˆHØ×%Ò%Ñ'Ô'Ð'ð	(ð 	(ð 	(ñ 	(ô 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(øøøð 	(ð 	(ð 	(ð 	(ð ×'Ò'¨¯ª©¬Ñ8Ô8Ð8s   Â 7C)Ã)
C3Ã6C3c                ó<  K  —  | j         |fddi|¤Ž}d}| j        �| j                             ¦   «         }d|› �ddœ}dd l}|                     |d¬	¦  «        4 ƒd {V —†}	t          |	d
| j        |¬¦  «        4 ƒd {V —†	 }
|
                     ¦   «         2 3 d {V —†}t          j	        |j
        ¦  «        }t          |d         ¦  «        dk    rŒ:|d         d         }t          |d         t          ¦  «        }|                     dd ¦  «        }|�d|ind }t          ||¬¦  «        }|r"|                     |j        |¬¦  «        ƒ d {V —† |W V — |� nŒÀ6 	 d d d ¦  «        ƒd {V —† n# 1 ƒd {V —†swxY w Y   d d d ¦  «        ƒd {V —† d S # 1 ƒd {V —†swxY w Y   d S )NrŸ   Tr[   r·   r¸   r¹   r   r»   r¼   rÎ   r¿   r‘   rÏ   r’   r“   rÐ   )r¨   r}   rÄ   rÅ   rÞ   rC   ry   Ú	aiter_sser¯   rÓ   rÔ   rÕ   ra   r   rR   r#   rÖ   r×   rØ   s                   r@   rÝ   zMiniMaxChat._astream[  sD  è è € ð 2�$Ô1°(ÐUÐUÀdÐUÈfÐUÐUˆØˆØÔÐ+ØÔ*×;Ò;Ñ=Ô=ˆGà0 wÐ0Ð0Ø.ð
ð 
ˆð 	ˆˆˆà×$Ò$¨W¸bÐ$ÑAÔAð 	ð 	ð 	ð 	ð 	ð 	ð 	ÀVÝ)Ø˜ Ô 5¸Gðñ ô ð ð ð ð ð ð ð ð àØ!-×!7Ò!7Ñ!9Ô!9ð ð ð ð ð ð ð ˜#Ý œJ s¤xÑ0Ô0�EÝ˜5 Ô+Ñ,Ô,°Ò1Ð1Ø Ø" 9Ô-¨aÔ0�FÝ;Ø˜wœ­ñô �Eð %+§J¢J¨ÀÑ$EÔ$E�Mð )Ð4ð )¨-Ð8Ð8à!ð $õ
 0Ø %°ðñ ô �Eð #ð TØ)×:Ò:¸5¼:ÈUÐ:ÑSÔSÐSÐSÐSÐSÐSÐSÐSØ�K�K�K�Kà$Ð0Ø˜ð 1ð- ":Ð!9ðð ð ñ ô ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð øøøð ð ð ð ð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	sC   ÁFÁ>E'ÂEÂB;E'ÅFÅ'
E1	Å1FÅ4E1	Å5FÆ
FÆFr¤   c                 óR   •— d„ |D ¦   «         } t          ¦   «         j        dd|i|¤ŽS )að  Bind tool-like objects to this chat model.

        Args:
            tools: A list of tool definitions to bind to this chat model.
                Can be a dictionary, pydantic model, callable, or BaseTool. Pydantic
                models, callables, and BaseTools will be automatically converted to
                their schema dictionary representation.
            **kwargs: Any additional parameters to pass to the
                :class: `~langchain.runnable.Runnable` constructor.
        c                 ó,   — g | ]}t          |¦  «        ‘ŒS rl   r+   )r‡   rM   s     r@   r£   z*MiniMaxChat.bind_tools.<locals>.<listcomp>™  s!   € ÐJÐJÐJ¸DÕ1°$Ñ7Ô7ÐJÐJÐJrX   r¤   rl   )ÚsuperÚbind)rh   r¤   r6   Úformatted_toolsrT   s       €r@   Ú
bind_toolszMiniMaxChat.bind_tools‰  s:   ø€ ð  KÐJÀEÐJÑJÔJˆØ�u‰wŒwŒ|Ð<Ð< /Ð<°VÐ<Ð<Ð<rX   )Úinclude_rawÚschemarè   c                ó
  — |rt          d|› �¦  «        ‚t          |t          ¦  «        ot          |t          ¦  «        }|                      |g¦  «        }|rt          |gd¬¦  «        }n,t          |¦  «        d         d         }t          |d¬¦  «        }|rht          j
        t          d¦  «        |z  d„ ¬	¦  «        }t          j
        d
„ ¬¦  «        }	|                     |	gd¬¦  «        }
t          |¬¦  «        |
z  S ||z  S )a‡  Model wrapper that returns outputs formatted to match the given schema.

        Args:
            schema: The output schema as a dict or a Pydantic class. If a Pydantic class
                then the model output will be an object of that class. If a dict then
                the model output will be a dict. With a Pydantic class the returned
                attributes will be validated, whereas with a dict they will not be. If
                `method` is "function_calling" and `schema` is a dict, then the dict
                must match the OpenAI function-calling spec.
            include_raw:
                If `False` then only the parsed structured output is returned.

                If an error occurs during model output parsing it will be raised.

                If `True` then both the raw model response (a `BaseMessage`) and the
                parsed model response will be returned.

                If an error occurs during output parsing it will be caught and returned
                as well.

                The final output is always a `dict` with keys `'raw'`, `'parsed'`, and
                `'parsing_error'`.

        Returns:
            A Runnable that takes any ChatModel input and returns as output:

                If include_raw is True then a dict with keys:
                    raw: BaseMessage
                    parsed: Optional[_DictOrPydantic]
                    parsing_error: Optional[BaseException]

                If include_raw is False then just _DictOrPydantic is returned,
                where _DictOrPydantic depends on the schema:

                If schema is a Pydantic class then _DictOrPydantic is the Pydantic
                    class.

                If schema is a dict then _DictOrPydantic is a dict.

        Example: Function-calling, Pydantic schema (method="function_calling", include_raw=False):
            .. code-block:: python

                from langchain_community.chat_models import MiniMaxChat
                from pydantic import BaseModel

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                llm = MiniMaxChat()
                structured_llm = llm.with_structured_output(AnswerWithJustification)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")

                # -> AnswerWithJustification(
                #     answer='A pound of bricks and a pound of feathers weigh the same.',
                #     justification='The weight of the feathers is much less dense than the weight of the bricks, but since both weigh one pound, they weigh the same.'
                # )

        Example: Function-calling, Pydantic schema (method="function_calling", include_raw=True):
            .. code-block:: python

                from langchain_community.chat_models import MiniMaxChat
                from pydantic import BaseModel

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                llm = MiniMaxChat()
                structured_llm = llm.with_structured_output(AnswerWithJustification, include_raw=True)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")

                # -> {
                #     'raw': AIMessage(content='', additional_kwargs={'tool_calls': [{'id': 'call_function_8953642285', 'type': 'function', 'function': {'name': 'AnswerWithJustification', 'arguments': '{"answer": "A pound of bricks and a pound of feathers weigh the same.", "justification": "The weight of the feathers is much less dense than the weight of the bricks, but since both weigh one pound, they weigh the same."}'}}]}, response_metadata={'token_usage': {'total_tokens': 257}, 'model_name': 'abab6.5-chat', 'finish_reason': 'tool_calls'}, id='run-d897e037-2796-49f5-847e-f9f69dd390db-0', tool_calls=[{'name': 'AnswerWithJustification', 'args': {'answer': 'A pound of bricks and a pound of feathers weigh the same.', 'justification': 'The weight of the feathers is much less dense than the weight of the bricks, but since both weigh one pound, they weigh the same.'}, 'id': 'call_function_8953642285', 'type': 'tool_call'}]),
                #     'parsed': AnswerWithJustification(answer='A pound of bricks and a pound of feathers weigh the same.', justification='The weight of the feathers is much less dense than the weight of the bricks, but since both weigh one pound, they weigh the same.'),
                #     'parsing_error': None
                # }

        Example: Function-calling, dict schema (method="function_calling", include_raw=False):
            .. code-block:: python

                from langchain_community.chat_models import MiniMaxChat
                from pydantic import BaseModel
                from langchain_core.utils.function_calling import convert_to_openai_tool

                class AnswerWithJustification(BaseModel):
                    '''An answer to the user question along with justification for the answer.'''
                    answer: str
                    justification: str

                dict_schema = convert_to_openai_tool(AnswerWithJustification)
                llm = MiniMaxChat()
                structured_llm = llm.with_structured_output(dict_schema)

                structured_llm.invoke("What weighs more a pound of bricks or a pound of feathers")

                # -> {
                #     'answer': 'A pound of bricks and a pound of feathers both weigh the same, which is a pound.',
                #     'justification': 'The difference is that bricks are much denser than feathers, so a pound of bricks will take up much less space than a pound of feathers.'
                # }
        zReceived unsupported arguments T)r¤   Úfirst_tool_onlyr¬   rN   )Úkey_namerë   Úrawc                 ó   — d S r†   rl   ©Ú_s    r@   ú<lambda>z4MiniMaxChat.with_structured_output.<locals>.<lambda>  s   € ÐRV€ rX   )ÚparsedÚparsing_errorc                 ó   — d S r†   rl   rï   s    r@   rñ   z4MiniMaxChat.with_structured_output.<locals>.<lambda>  s   € Àd€ rX   )rò   ró   )Úexception_key)rí   )rÂ   rP   r«   Ú
issubclassr.   rç   r!   r,   r    r'   Úassignr   Úwith_fallbacksr&   )rh   ré   rè   r6   Úis_pydantic_schemaÚllmÚoutput_parserrì   Úparser_assignÚparser_noneÚparser_with_fallbacks              r@   Úwith_structured_outputz"MiniMaxChat.with_structured_outputœ  sB  € ð` ð 	IÝÐG¸vÐGÐGÑHÔHÐHÝ'¨µÑ5Ô5ÐW½*ÀVÍYÑ:WÔ:WÐØ�oŠo˜v˜hÑ'Ô'ˆØð 		Ý.AØ�hØ $ð/ñ /ô /ˆMˆMõ
 .¨fÑ5Ô5°jÔAÀ&ÔIˆHÝ4Ø!°4ðñ ô ˆMð ð 
	'Ý/Ô6Ý! %Ñ(Ô(¨=Ñ8ÈÈðñ ô ˆMõ .Ô4¸N¸NÐKÑKÔKˆKØ#0×#?Ò#?Ø�¨_ð $@ñ $ô $Ð õ  3Ð'Ñ'Ô'Ð*>Ñ>Ð>à˜Ñ&Ð&rX   )F)NNN)NN)>rU   Ú
__module__Ú__qualname__Ú__doc__Úpropertyr	   r®   r   ri   rm   rf   rs   Ú__annotations__re   ro   Úintrp   Úfloatrq   r0   rš   rr   ry   r{   r   r}   r1   r~   Úboolr/   Úmodel_configr2   Úclassmethodr�   r   r.   r$   r�   r   r   r¨   Ústaticmethodr¥   r   rÌ   r
   r#   rÃ   r   rß   r   rÝ   r   r   r   r(   r%   r   r   rç   rÿ   Ú__classcell__)rT   s   @r@   rc   rc   ž   s|  ø€ € € € € € ð~ð ~ð@ ðA T¨#¨s¨(¤^ð Að Að Añ „XðAð ð˜3ð ð ð ñ „Xðð ð
  c¨3 h¤ð 
ð 
ð 
ñ „Xð
ð €GˆSÐÐÑØ €Eˆ3Ð Ð Ñ ØØ€J�ÐÐÑØAØ€K�ÐÐÑØQØ€Eˆ5ÐÐÑØDØ#( 5¸Ð#>Ñ#>Ô#>€L�$�s˜C�x”.Ð>Ð>Ñ>ØVØ!˜EØEÈZðñ ô Ð�cð ð ñ ð ', e°DÀ
Ð&KÑ&KÔ&KÐ�h˜s”mÐKÐKÑKØJØ!& ¨YÐ!7Ñ!7Ô!7€O�YÐ7Ð7Ñ7ØØ€IˆtÐÐÑØ/à�:Øðñ ô €Lð €_˜(Ð#Ñ#Ô#Øð¨$ð °3ð ð ð ñ „[ñ $Ô#ðð4J¨E°$¸	°/Ô,Bð JÀzð Jð Jð Jð Jð$ >Cðð Ø˜[Ô)ðØ6:ðØNQðà	ˆc�3ˆhŒðð ð ð ð  ð°°c¸3°h´ð ÀDð ð ð ñ „\ðð %)Ø:>Ø!%ð49ð 49à�{Ô#ð49ð �t˜C”yÔ!ð49ð Ð6Ô7ð	49ð
 ˜”ð49ð ð49ð 
ð49ð 49ð 49ð 49ðr %)Ø:>ð	-ð -à�{Ô#ð-ð �t˜C”yÔ!ð-ð Ð6Ô7ð	-ð
 ð-ð 
Ð%Ô	&ð-ð -ð -ð -ðd %)Ø?CØ!%ð9ð 9à�{Ô#ð9ð �t˜C”yÔ!ð9ð Ð;Ô<ð	9ð
 ˜”ð9ð ð9ð 
ð9ð 9ð 9ð 9ðH %)Ø?Cð	,ð ,à�{Ô#ð,ð �t˜C”yÔ!ð,ð Ð;Ô<ð	,ð
 ð,ð 
Ð*Ô	+ð,ð ,ð ,ð ,ð\=à˜˜d 3¨ 8œn¨d°9¬o¸xÈÐQÔRÔSð=ð ð=ð 
Ð$ iÐ/Ô	0ð	=ð =ð =ð =ð =ð =ð. "ð	I'ð I'ð I'à�d˜D œOÐ+Ô,ðI'ð ð	I'ð
 ðI'ð 
Ð$ e¨D°)¨OÔ&<Ð<Ô	=ðI'ð I'ð I'ð I'ð I'ð I'ð I'ð I'rX   rc   )Lr  r¯   ÚloggingÚ
contextlibr   r   Úoperatorr   Útypingr   r   r   r	   r
   r   r   r   r   r   Úlangchain_core.callbacksr   r   Úlangchain_core.language_modelsr   Ú*langchain_core.language_models.chat_modelsr   r   r   Úlangchain_core.messagesr   r   r   r   r   r   r   r   r   Ú"langchain_core.output_parsers.baser   Ú*langchain_core.output_parsers.openai_toolsr    r!   Úlangchain_core.outputsr"   r#   r$   Úlangchain_core.runnablesr%   r&   r'   Úlangchain_core.toolsr(   Úlangchain_core.utilsr)   r*   Ú%langchain_core.utils.function_callingr,   Úlangchain_core.utils.pydanticr-   Úpydanticr.   r/   r0   r1   r2   Ú	getLoggerrU   Úloggerr®   rA   rC   rW   r]   ra   rc   rl   rX   r@   ú<module>r     s  ðØ )Ð )à €€€Ø €€€Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð >Ð =Ð =Ð =Ð =Ð =ðð ð ð ð ð ð ð ð ð ð

ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð @Ð ?Ð ?Ð ?Ð ?Ð ?ðð ð ð ð ð ð ð ð SÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RØ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ )Ð )Ð )Ð )Ð )Ð )Ø LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ HÐ HÐ HÐ HÐ HÐ HØ 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 
ˆÔ	˜8Ñ	$Ô	$€ð ð$˜cð $¨3ð $°Sð $ÀCð $ÈHð $ð $ð $ñ „ð$ð$ ð$Øð$Øð$Ø#&ð$Ø25ð$àð$ð $ð $ñ Ôð$ð( kð °d¸3À¸8´nð ð ð ð ð2
3 $ s¨C x¤.ð 
3°[ð 
3ð 
3ð 
3ð 
3ð*Ø	ˆc�3ˆhŒð*Ø(,Ð-=Ô(>ð*àð*ð *ð *ð *ð"G
'ð G
'ð G
'ð G
'ð G
'�-ñ G
'ô G
'ð G
'ð G
'ð G
'rX   