
    Ng+u                     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         c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/chat_models/minimax.pyconnect_httpx_sserA   ?   s       &%%%%%	vs	-	-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}VS33F33 $ $ $ $ $ $ $xk(######$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   A  
A
A
messagec                    t          | t                    rd| j        d}nt          | t                    r$d| j        | j                            d          d}nt          | 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	GY	'	' M!377EE
 

 
G]	+	+ 
M (W_EE	G[	)	) M#0LIG$=$A$A&$I$I	
 
 KW->-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    776??Dggi$$G{WW\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     776??Dggi$$Gd++J*4,'{m~==gAR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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7DJ'@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.5-chatre      ro   gffffff?rp   gffffff?rq   )default_factoryrr   z2https://api.minimax.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.s9~>>G"1I1IJJJOwPPP    ll7B//&*
 

 kjIIIIrX   messages	is_streamc                     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GhGGG&+
**6::gr+B+BCCC      	% $GH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$\2C7 7- 6:ZZ(66 6$\2		 	rX   stoprun_managerr=   r6   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   |                     |                                          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   )
ValueErrorr~   _streamr   r   r}   get_secret_valuehttpxClientpostry   raise_for_statusr   r   rh   r   r   r   r=   r6   r   stream_iterr   r|   r   r   r3   r?   s                 r@   	_generatezMiniMaxChat._generate  s   ,  	L   %0FFdn	 	5&$,# @F K (4441$1(EEfEE+*;;==G0w00.
 
 	\\'2\66 	(&{{4#8w{GGH%%'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( ''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UdUfUU+*;;==G0w00.
 
 	\\'2\66 	&" 5G   '0022  C Jsx00E5+,,11 "9-a0F;w E %+JJ$E$EM )4 )-88! $
 0 %  E # N#44UZu4MMMKKK$0 13              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	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   r   s                 r@   
_ageneratezMiniMaxChat._agenerate4  s       	L   %0FFdn	 	<'$-# @F K /{;;;;;;;;;1$1(EEfEE+*;;==G0w00.
 
 	$$Wb$AA 	( 	( 	( 	( 	( 	( 	(V#[[)>W[MMMMMMMMH%%'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( ''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._astreamU  sD      2$1(UUdUfUU+*;;==G0w00.
 
 	$$Wb$AA 	 	 	 	 	 	 	V) 5G          !-!7!7!9!9       # Jsx00E5+,,11 "9-a0F;w E %+JJ$E$EM )4 )-88! $
 0 %  E # T)::5:U:SSSSSSSSSKKKK$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JD1$77JJJrX   r   rl   )superbind)rh   r   r6   formatted_toolsrT   s       r@   
bind_toolszMiniMaxChat.bind_tools  s:      KJEJJJuww|<</<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 )aE  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   R  	IGvGGHHH'55W*VY:W:Woovh'' 		.Ah $/ / /MM
 .f55jA&IH4!4  M  
	'/6!%((=8  M .4NNKKKK#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   __classcell__)rT   s   @r@   rc   rc      st        ~ ~@ AT#s(^ A A A XA 3    X 
c3h 
 
 
 X
 GSE3JAKQE5D#(5#>#>#>L$sCx.>>>V!EDJ  c    ',eD
&K&K&KhsmKKKJ!&Y!7!7!7OY777It/:  L _(###$ 3    [ $#4JE$	/,B Jz J J J J$ >C [)6:	c3h     c3h D    \ %):>!%.9 .9{#.9 tCy!.9 67	.9
 .9 .9 
.9 .9 .9 .9f %):>	- -{#- tCy!- 67	-
 - 
%	&- - - -d %)?C!%9 9{#9 tCy!9 ;<	9
 9 9 
9 9 9 9H %)?C	, ,{#, tCy!, ;<	,
 , 
*	+, , , ,\=d38nd9oxQRS= = 
$k1	2	= = = = = =. "	B' B' B'dDO+,B' 	B'
 B' 
$eD)O&<<	=B' B' B' B' B' B' B' B'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 d38n    2
3$sCx. 
3[ 
3 
3 
3 
3*	c3h*(,-=(>** * * *"z	' z	' z	' z	' z	'- z	' z	' z	' z	' z	'rX   