
    
iJ              
      L   U d Z ddlmZ ddlZddlZddl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mZ ddlmZmZ ddlmZmZmZ dd	lmZ er,dd
lmZmZmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ d~dZ,i ddde,fddde,fddde,fd d!d"e,fd#dd$e,fd%dd&e,fd'd(d)e,fd*d+d,e,fd-d.d/e,fd0d1d2e,fd3d4d5e,fd6d7d8e,fd9d:d;e,fd<d=d>d? fd@dAdBdC fdDdEdFe,fdGdHdIe,fdJdKe,fd!dLe,fdMdNe,fdOdPe,fdQdRe,fdSdTe,fdUdVe,fdWZ-dXe.dY<   	 dd^Z/ ej0         e1e-          _          ddb            Z2eddddcddj            Z3e	 dddddcddl            Z3e	 dddmddcddo            Z3	 dddddcddrZ3ddsddtZ4ddvZ5ddxZ6dd{Z7d|Z8 G d} dkeeef                   Z9dS )z"Factory functions for chat models.    )annotationsN)TYPE_CHECKINGAnyLiteral	TypeAliascastoverload)BaseChatModelLanguageModelInput)	AIMessage
AnyMessage)ChatPromptValueConcreteStringPromptValue)RunnableRunnableConfigensure_config)override)AsyncIteratorCallableIteratorSequence)
ModuleType)StreamEvent)BaseTool)RunLogRunLogPatch)	BaseModelclstype[BaseChatModel]kwargsr   returnr
   c                     | di |S N r$   )r   r    s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain/chat_models/base.py_callr&   !   s    3====    	anthropiclangchain_anthropicChatAnthropicanthropic_bedrocklangchain_awsChatAnthropicBedrockazure_aizlangchain_azure_ai.chat_modelsAzureAIChatCompletionsModelazure_openailangchain_openaiAzureChatOpenAIbedrockChatBedrockbedrock_converseChatBedrockConversecoherelangchain_cohere
ChatCoheredeepseeklangchain_deepseekChatDeepSeek	fireworkslangchain_fireworksChatFireworksgoogle_anthropic_vertexz&langchain_google_vertexai.model_gardenChatAnthropicVertexgoogle_genailangchain_google_genaiChatGoogleGenerativeAIgoogle_vertexailangchain_google_vertexaiChatVertexAIgroqlangchain_groqChatGroqhuggingfacelangchain_huggingfaceChatHuggingFacec                      | j         dd|i|S Nmodel_idr$   )from_model_idr   modelr    s      r%   <lambda>rT   ;   s    %6S%6%P%P%P%P%P r'   ibmlangchain_ibmChatWatsonxc                     | dd|i|S rO   r$   rR   s      r%   rT   rT   @   s    SS%B%B%%B6%B%B r'   	mistralailangchain_mistralaiChatMistralAInvidialangchain_nvidia_ai_endpoints
ChatNVIDIAlangchain_ollama
ChatOllama
ChatOpenAIlangchain_openrouterChatOpenRouterlangchain_perplexityChatPerplexitylangchain_togetherChatTogetherlangchain_upstageChatUpstagelangchain_xaiChatXAI)ollamaopenai
openrouter
perplexitytogetherupstagexaiz8dict[str, tuple[str, str, Callable[..., BaseChatModel]]]_BUILTIN_PROVIDERSmodulestr
class_namer   c                    	 t          j        |           S # t          $ rR}|                     dd          d                             dd          }d| d| d	| d
}t          |          |d}~ww xY w)a  Import a module by name.

    Args:
        module: The fully qualified module name to import (e.g., `'langchain_openai'`).
        class_name: The name of the class being imported, used for error messages.

    Returns:
        The imported module.

    Raises:
        ImportError: If the module cannot be imported, with a message suggesting
            the pip package to install.
    .   maxsplitr   _-zInitializing z requires the z. package. Please install it with `pip install `N)	importlibimport_moduleImportErrorsplitreplace)rt   rv   epkgmsgs        r%   _import_moduler   e   s    
&&v... & & & ll3l++A.66sC@@(J ( (c ( (!$( ( ( 	 #A%&s    
A2AA--A2)maxsizeproviderCallable[..., BaseChatModel]c                   | t           vrCd                    t                                                     }d| d| }t          |          t           |          \  }}}	 t	          ||          }nA# t
          $ r4}| dk    r 	 t	          d|          }n# t
          $ r |dw xY wY d}~nd}~ww xY wt          ||          }t          j        ||          S )aJ  Return a factory function that creates a chat model for the given provider.

    This function is cached to avoid repeated module imports.

    Args:
        provider: The name of the model provider (e.g., `'openai'`, `'anthropic'`).

            Must be a key in `_BUILTIN_PROVIDERS`.

    Returns:
        A callable that accepts model kwargs and returns a `BaseChatModel` instance for
            the specified provider.

    Raises:
        ValueError: If the provider is not in `_BUILTIN_PROVIDERS`.
        ImportError: If the provider's integration package is not installed.
    , zUnsupported provider=z".

Supported model providers are: rl   zlangchain_community.chat_modelsN)r   )	rs   joinkeys
ValueErrorr   r   getattr	functoolspartial)	r   	supportedr   r   rv   creator_funcrt   r   r   s	            r%   _get_chat_model_creatorr      s   * )))II0557788	WXWWIWWoo$6x$@!C\Z00 	 	 	x	#$EzRRFF 	 	 	 	 FFFF	 &*
%
%C\s3333s0   A0 0
B.:B)BB)B!!B))B.)model_providerconfigurable_fieldsconfig_prefixrS   r   
str | Noner   Noner   c                   d S Nr$   rS   r   r   r   r    s        r%   init_chat_modelr      s	     Cr'   _ConfigurableModelc                   d S r   r$   r   s        r%   r   r      	     r'   .,Literal['any'] | list[str] | tuple[str, ...]c                   d S r   r$   r   s        r%   r   r      r   r'   3Literal['any'] | list[str] | tuple[str, ...] | None"BaseChatModel | _ConfigurableModelc               L   | <t          | t                    s'dt          |           j         d}t	          |          | s|sd}|pd}|r|st          j        d|dd	           |st          t          d
|           fd|i|S | r| |d<   |r||d<   t          |||          S )u\/  Initialize a chat model from any supported provider using a unified interface.

    **Two main use cases:**

    1. **Fixed model** – specify the model upfront and get a ready-to-use chat model.
    2. **Configurable model** – choose to specify parameters (including model name) at
        runtime via `config`. Makes it easy to switch between models/providers without
        changing your code

    !!! note "Installation requirements"

        Requires the integration package for the chosen model provider to be installed.

        See the `model_provider` parameter below for specific package names
        (e.g., `pip install langchain-openai`).

        Refer to the [provider integration's API reference](https://docs.langchain.com/oss/python/integrations/providers)
        for supported model parameters to use as `**kwargs`.

    Args:
        model: The model name, optionally prefixed with provider (e.g., `'openai:gpt-4o'`).

            Prefer exact model IDs from provider docs over aliases for reliable behavior
            (e.g., dated versions like `'...-20250514'` instead of `'...-latest'`).

            Will attempt to infer `model_provider` from model if not specified.

            The following providers will be inferred based on these model prefixes:

            - `gpt-...` | `o1...` | `o3...`       -> `openai`
            - `claude...`                         -> `anthropic`
            - `amazon...`                         -> `bedrock`
            - `gemini...`                         -> `google_vertexai`
            - `command...`                        -> `cohere`
            - `accounts/fireworks...`             -> `fireworks`
            - `mistral...`                        -> `mistralai`
            - `deepseek...`                       -> `deepseek`
            - `grok...`                           -> `xai`
            - `sonar...`                          -> `perplexity`
            - `solar...`                          -> `upstage`
        model_provider: The model provider if not specified as part of the model arg
            (see above).

            Supported `model_provider` values and the corresponding integration package
            are:

            - `openai`                  -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
            - `anthropic`               -> [`langchain-anthropic`](https://docs.langchain.com/oss/python/integrations/providers/anthropic)
            - `azure_openai`            -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
            - `azure_ai`                -> [`langchain-azure-ai`](https://docs.langchain.com/oss/python/integrations/providers/microsoft)
            - `google_vertexai`         -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
            - `google_genai`            -> [`langchain-google-genai`](https://docs.langchain.com/oss/python/integrations/providers/google)
            - `anthropic_bedrock`       -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
            - `bedrock`                 -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
            - `bedrock_converse`        -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
            - `cohere`                  -> [`langchain-cohere`](https://docs.langchain.com/oss/python/integrations/providers/cohere)
            - `fireworks`               -> [`langchain-fireworks`](https://docs.langchain.com/oss/python/integrations/providers/fireworks)
            - `together`                -> [`langchain-together`](https://docs.langchain.com/oss/python/integrations/providers/together)
            - `mistralai`               -> [`langchain-mistralai`](https://docs.langchain.com/oss/python/integrations/providers/mistralai)
            - `huggingface`             -> [`langchain-huggingface`](https://docs.langchain.com/oss/python/integrations/providers/huggingface)
            - `groq`                    -> [`langchain-groq`](https://docs.langchain.com/oss/python/integrations/providers/groq)
            - `ollama`                  -> [`langchain-ollama`](https://docs.langchain.com/oss/python/integrations/providers/ollama)
            - `google_anthropic_vertex` -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
            - `deepseek`                -> [`langchain-deepseek`](https://docs.langchain.com/oss/python/integrations/providers/deepseek)
            - `ibm`                     -> [`langchain-ibm`](https://docs.langchain.com/oss/python/integrations/providers/ibm)
            - `nvidia`                  -> [`langchain-nvidia-ai-endpoints`](https://docs.langchain.com/oss/python/integrations/providers/nvidia)
            - `xai`                     -> [`langchain-xai`](https://docs.langchain.com/oss/python/integrations/providers/xai)
            - `openrouter`              -> [`langchain-openrouter`](https://docs.langchain.com/oss/python/integrations/providers/openrouter)
            - `perplexity`              -> [`langchain-perplexity`](https://docs.langchain.com/oss/python/integrations/providers/perplexity)
            - `upstage`                 -> [`langchain-upstage`](https://docs.langchain.com/oss/python/integrations/providers/upstage)

        configurable_fields: Which model parameters are configurable at runtime:

            - `None`: No configurable fields (i.e., a fixed model).
            - `'any'`: All fields are configurable. **See security note below.**
            - `list[str] | Tuple[str, ...]`: Specified fields are configurable.

            Fields are assumed to have `config_prefix` stripped if a `config_prefix` is
            specified.

            If `model` is specified, then defaults to `None`.

            If `model` is not specified, then defaults to `("model", "model_provider")`.

            !!! warning "Security note"

                Setting `configurable_fields="any"` means fields like `api_key`,
                `base_url`, etc., can be altered at runtime, potentially redirecting
                model requests to a different service/user.

                Make sure that if you're accepting untrusted configurations that you
                enumerate the `configurable_fields=(...)` explicitly.

        config_prefix: Optional prefix for configuration keys.

            Useful when you have multiple configurable models in the same application.

            If `'config_prefix'` is a non-empty string then `model` will be configurable
            at runtime via the `config["configurable"]["{config_prefix}_{param}"]` keys.
            See examples below.

            If `'config_prefix'` is an empty string then model will be configurable via
            `config["configurable"]["{param}"]`.
        **kwargs: Additional model-specific keyword args to pass to the underlying
            chat model's `__init__` method. Common parameters include:

            - `temperature`: Model temperature for controlling randomness.
            - `max_tokens`: Maximum number of output tokens.
            - `timeout`: Maximum time (in seconds) to wait for a response.
            - `max_retries`: Maximum number of retry attempts for failed requests.
            - `base_url`: Custom API endpoint URL.
            - `rate_limiter`: A
                [`BaseRateLimiter`][langchain_core.rate_limiters.BaseRateLimiter]
                instance to control request rate.

            Refer to the specific model provider's
            [integration reference](https://reference.langchain.com/python/integrations/)
            for all available parameters.

    Returns:
        A `BaseChatModel` corresponding to the `model_name` and `model_provider`
            specified if configurability is inferred to be `False`. If configurable, a
            chat model emulator that initializes the underlying model at runtime once a
            config is passed in.

    Raises:
        ValueError: If `model_provider` cannot be inferred or isn't supported.
        ImportError: If the model provider integration package is not installed.

    ???+ example "Initialize a non-configurable model"

        ```python
        # pip install langchain langchain-openai langchain-anthropic langchain-google-vertexai

        from langchain.chat_models import init_chat_model

        o3_mini = init_chat_model("openai:o3-mini", temperature=0)
        claude_sonnet = init_chat_model("anthropic:claude-sonnet-4-5-20250929", temperature=0)
        gemini_2-5_flash = init_chat_model("google_vertexai:gemini-2.5-flash", temperature=0)

        o3_mini.invoke("what's your name")
        claude_sonnet.invoke("what's your name")
        gemini_2-5_flash.invoke("what's your name")
        ```

    ??? example "Partially configurable model with no default"

        ```python
        # pip install langchain langchain-openai langchain-anthropic

        from langchain.chat_models import init_chat_model

        # (We don't need to specify configurable=True if a model isn't specified.)
        configurable_model = init_chat_model(temperature=0)

        configurable_model.invoke("what's your name", config={"configurable": {"model": "gpt-4o"}})
        # Use GPT-4o to generate the response

        configurable_model.invoke(
            "what's your name",
            config={"configurable": {"model": "claude-sonnet-4-5-20250929"}},
        )
        ```

    ??? example "Fully configurable model with a default"

        ```python
        # pip install langchain langchain-openai langchain-anthropic

        from langchain.chat_models import init_chat_model

        configurable_model_with_default = init_chat_model(
            "openai:gpt-4o",
            configurable_fields="any",  # This allows us to configure other params like temperature, max_tokens, etc at runtime.
            config_prefix="foo",
            temperature=0,
        )

        configurable_model_with_default.invoke("what's your name")
        # GPT-4o response with temperature 0 (as set in default)

        configurable_model_with_default.invoke(
            "what's your name",
            config={
                "configurable": {
                    "foo_model": "anthropic:claude-sonnet-4-5-20250929",
                    "foo_temperature": 0.6,
                }
            },
        )
        # Override default to use Sonnet 4.5 with temperature 0.6 to generate response
        ```

    ??? example "Bind tools to a configurable model"

        You can call any chat model declarative methods on a configurable model in the
        same way that you would with a normal model:

        ```python
        # pip install langchain langchain-openai langchain-anthropic

        from langchain.chat_models import init_chat_model
        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")


        configurable_model = init_chat_model(
            "gpt-4o", configurable_fields=("model", "model_provider"), temperature=0
        )

        configurable_model_with_tools = configurable_model.bind_tools(
            [
                GetWeather,
                GetPopulation,
            ]
        )
        configurable_model_with_tools.invoke(
            "Which city is hotter today and which is bigger: LA or NY?"
        )
        # Use GPT-4o

        configurable_model_with_tools.invoke(
            "Which city is hotter today and which is bigger: LA or NY?",
            config={"configurable": {"model": "claude-sonnet-4-5-20250929"}},
        )
        # Use Sonnet 4.5
        ```

    Nz6`model` must be a string (e.g., 'openai:gpt-4o'), got zp. If you've already constructed a chat model object, use it directly instead of passing it to init_chat_model().)rS   r    zconfig_prefix=z has been set but no fields are configurable. Set `configurable_fields=(...)` to specify the model params that are configurable.   )
stacklevelru   r   rS   )default_configr   r   )

isinstanceru   type__name__	TypeErrorwarningswarn_init_chat_model_helperr   r   )rS   r   r   r   r    r   s         r%   r   r      s;   p E3!7!7SE{{#S S S 	
 nn :, :9!'RM 
0 
}    		
 	
 	
 	
  
&
 
)
 
 
 	

   w 2#1 #/   r'   )r   c               Z    t          | |          \  } }t          |          } |dd| i|S )NrS   r$   )_parse_modelr   )rS   r   r    r   s       r%   r   r     s@     )??E>*>::L<..e.v...r'   
model_namec                6   |                                  t          fddD                       rdS                     d          rdS                     d          rdS                     d          rd	S                     d
          rdS                     d          rdS                     d          rdS                     d          rdS                     d          rdS                     d          rdS                     d          rdS dS )zAttempt to infer model provider from model name.

    Args:
        model_name: The name of the model to infer provider for.

    Returns:
        The inferred provider name, or `None` if no provider could be inferred.
    c              3  B   K   | ]}                     |          V  d S r   )
startswith).0premodel_lowers     r%   	<genexpr>z0_attempt_infer_model_provider.<locals>.<genexpr>  sE       	 	 	s##	 	 	 	 	 	r'   )zgpt-o1o3chatgptztext-davincirm   clauder(   commandr7   zaccounts/fireworksr=   geminirE   )zamazon.z
anthropic.zmeta.r3   )mistralmixtralrY   r:   grokrr   sonarro   solarrq   N)loweranyr   )r   r   s    @r%   _attempt_infer_model_providerr     s    ""$$K  	 	 	 	
	 	 	 	 	 
 x h'' { i(( x 233 { h'' !   @AA y 455 { j)) z f%% u g&& | g&& y4r'   tuple[str, str]c                   |sud| v rq|                      dd          d         t          v rM|                      dd          d         }d                    |                      d          dd                   } |pt          |           }|s?d                    t	          t                              }d| d| d	}t          |          |                    d
d                                          }| |fS )z?Parse model name and provider, inferring provider if necessary.:ry   rz   r   Nr   z)Unable to infer model provider for model=zB. Please specify 'model_provider' directly.

Supported providers: ze

For help with specific providers, see: https://docs.langchain.com/oss/python/integrations/providersr}   r|   )r   rs   r   r   sortedr   r   r   )rS   r   supported_listr   s       r%   r   r   9  s    /5LLKKaK((+/AAAS155a8S))!""-.. $K'DU'K'KN 
6*<#=#=>>L% L L$2L L L 	 oo $++C55;;==N.  r'   sprefixc                ,    |                      |          S r   )removeprefix)r   r   s     r%   _remove_prefixr   X  s    >>&!!!r'   )
bind_toolswith_structured_outputc                  b    e Zd Zdddddd]dZd^dZd_d`dZdadZ	 d_dbdZee	dcd                        Z
e		 d_ddd             Ze		 d_ddd!            Ze		 d_ded$            Ze		 d_dfd&            Z	 d_d'd(dg fd/Z	 d_d'd(dg fd0Z	 d_d'd(dh fd4Z	 d_d'd(di fd6Ze		 d_djd8            Ze		 d_dkd:            Zee		 d_d;d;ddddddd<dldH                        Zee		 d_d;dddddddIdmdL                        Ze		 d_d;d;ddddddd<dndN            Ze		 d_dOdddddddPdodT            ZdpdXZdqd\Z xZS )rr   Nr   r   r$   r   r   r   queued_declarative_operationsr   dict[str, Any] | Noner   r   r   ru   r   5Sequence[tuple[str, tuple[Any, ...], dict[str, Any]]]r!   r   c                   |pi | _         |dk    rdnt          |          | _        |r|                    d          s|dz   n|| _        t          |          | _        d S )Nr   r|   )_default_configlist_configurable_fieldsendswith_config_prefix_queued_declarative_operations)selfr   r   r   r   s        r%   __init__z_ConfigurableModel.__init__`  s     0>/C(E11EEt<O7P7P 	!
 %2%;%;C%@%@MC 	 -  	+++r'   namer   c                     t           v r	d
 fd}|S  j        r6                                 x}r t          |          rt	          |          S  d} j        r|dz  }|d	z  }t          |          )Nargsr   r    r!   r   c                    t          j                  }|                    | |f           t          t	          j                  t          j        t                     rt          j                  nj        j        |          S )Nr   )	r   r   appendr   dictr   r   r   r   )r   r    r   r   r   s      r%   queuez-_ConfigurableModel.__getattr__.<locals>.queue~  s    0471 1- .44dD&5IJJJ)#'(<#=#=!$";TBB)3T-F(G(G(G2"&"52O   r'   z! is not a BaseChatModel attributez, and is not implemented on the default modelrx   )r   r   r    r   r!   r   )_DECLARATIVE_METHODSr   _modelhasattrr   AttributeError)r   r   r   rS   r   s   ``   r%   __getattr__z_ConfigurableModel.__getattr__w  s    '''       L 	(dkkmm%;U 	(PTAUAU 	(5$'''888 	BAACs
S!!!r'   configRunnableConfig | NoneRunnable[Any, Any]c                    i | j         |                     |          }t          di |}| j        D ]\  }}} t	          ||          |i |}|S r#   )r   _model_paramsr   r   r   )r   r   paramsrS   r   r   r    s          r%   r   z_ConfigurableModel._model  ss    GD(GD,>,>v,F,FG'11&11"&"E 	: 	:D$(GE4(($9&99EEr'   dict[str, Any]c                     t          |          } fd|                    di                                           D             } j        dk    r  fd|                                D             }|S )Nc                v    i | ]5\  }}|                     j                  t          |j                  |6S r$   )r   r   r   r   kvr   s      r%   
<dictcomp>z4_ConfigurableModel._model_params.<locals>.<dictcomp>  sQ     
 
 
1||D/00
1d122A
 
 
r'   configurabler   c                .    i | ]\  }}|j         v ||S r$   )r   r   s      r%   r   z4_ConfigurableModel._model_params.<locals>.<dictcomp>  s,    dddTQQ$JcEcEcAqEcEcEcr'   )r   getitemsr   )r   r   model_paramss   `  r%   r   z _ConfigurableModel._model_params  s    v&&
 
 
 


>266<<>>
 
 

 $--dddd\-?-?-A-AdddLr'   r    c                >    t          di |pi t          d|          }t          |          }                     |          d |                                D             } fd|                    di                                           D             |d<   t           j                  }|r|                    ddd|if           t          i  j
        t           j        t                    rt           j                  n j         j        |          S )	Nr   c                &    i | ]\  }}|d k    ||S )r   r$   )r   r   r   s      r%   r   z2_ConfigurableModel.with_config.<locals>.<dictcomp>  s(    SSSTQqN?R?RAq?R?R?Rr'   c                J    i | ]\  }}t          |j                  v|| S r$   )r   r   )r   r   r   r  r   s      r%   r   z2_ConfigurableModel.with_config.<locals>.<dictcomp>  sA     ,
 ,
 ,
1a!455\II qIIIr'   r   with_configr$   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r    remaining_configr   r  s   `    @r%   r  z_ConfigurableModel.with_config  sZ   
  SS6<RSD9I64R4RSSv&&))&11SSV\\^^SSS,
 ,
 ,
 ,
 ,


>266<<>>,
 ,
 ,
(
 )-T-P(Q(Q% 	)00!/0   "Cd2ClC$3T::!+T%> ? ? ?*-*G
 
 
 	
r'   r   c                V    t           t          z  t          z  t          t                   z  S )z'Get the input type for this `Runnable`.)ru   r   r   r   r   )r   s    r%   	InputTypez_ConfigurableModel.InputType  s      &&)@@4
CSSSr'   inputr   c                H     |                      |          j        |fd|i|S Nr   )r   invoker   r	  r   r    s       r%   r  z_ConfigurableModel.invoke  s0     *t{{6"")%III&IIIr'   c                X   K    |                      |          j        |fd|i| d {V S r  )r   ainvoker  s       r%   r  z_ConfigurableModel.ainvoke  sF       1T[[((0PPvPPPPPPPPPPr'   
Any | NoneIterator[Any]c              +  \   K    |                      |          j        |fd|i|E d {V  d S r  )r   streamr  s       r%   r  z_ConfigurableModel.stream  sL       .4;;v&&-eMMFMfMMMMMMMMMMMr'   AsyncIterator[Any]c               l   K    |                      |          j        |fd|i|2 3 d {V }|W V  6 d S r  )r   astreamr   r	  r   r    xs        r%   r  z_ConfigurableModel.astream  so       3t{{6**25RRR6RR 	 	 	 	 	 	 	!GGGGG SRR   3F)return_exceptionsinputslist[LanguageModelInput],RunnableConfig | list[RunnableConfig] | Noner  bool	list[Any]c                  |pd }|(t          |t                    st          |          dk    rAt          |t                    r|d         } |                     |          j        |f||d|S  t                      j        |f||d|S Nry   r   r   r  )r   r   lenr   r   batchsuperr   r  r   r  r    	__class__s        r%   r$  z_ConfigurableModel.batch  s     4>Z55>V9I9I&$'' #,4;;v&&,"3  	   uww}
/
 
 	
 
 	
r'   c               8  K   |pd }|(t          |t                    st          |          dk    rGt          |t                    r|d         } |                     |          j        |f||d| d {V S  t                      j        |f||d| d {V S r!  )r   r   r#  r   r   abatchr%  r&  s        r%   r)  z_ConfigurableModel.abatch  s      4>Z55>V9I9I&$'' #3V,,3"3  	         $UWW^
/
 
 	
 
 
 
 
 
 
 
 	
r'   Sequence[LanguageModelInput]0RunnableConfig | Sequence[RunnableConfig] | None%Iterator[tuple[int, Any | Exception]]c             +  \  K   |pd }|(t          |t                    st          |          dk    rWt          |t                    r|d         } |                     t          d|                    j        |f||d|E d {V  d S  t                      j        |f||d|E d {V  d S Nry   r   r   r"  )r   r   r#  r   r   r   batch_as_completedr%  r&  s        r%   r/  z%_ConfigurableModel.batch_as_completed.  s%      4>Z55>V9I9I&$'' #Ut{{4(8&#A#ABBU"3  	           2uww1"3  	          r'   AsyncIterator[tuple[int, Any]]c              |  K   |pd }|(t          |t                    st          |          dk    r_t          |t                    r|d         } |                     t          d|                    j        |f||d|2 3 d {V }|W V  6 d S  t                      j        |f||d|2 3 d {V }|W V  6 d S r.  )r   r   r#  r   r   r   abatch_as_completedr%  )r   r  r   r  r    r  r'  s         r%   r2  z&_ConfigurableModel.abatch_as_completedK  sZ      4>Z55>V9I9I&$'' #"4;;%v.. ! "3          a    75776"3  	        a   s   B.B;Iterator[LanguageModelInput]c              +  \   K    |                      |          j        |fd|i|E d {V  d S r  )r   	transformr  s       r%   r5  z_ConfigurableModel.transforml  sL       14;;v&&0PPvPPPPPPPPPPPPr'   !AsyncIterator[LanguageModelInput]c               l   K    |                      |          j        |fd|i|2 3 d {V }|W V  6 d S r  )r   
atransformr  s        r%   r8  z_ConfigurableModel.atransformu  so       6t{{6**5eUUFUfUU 	 	 	 	 	 	 	!GGGGG VUUr  T)diffwith_streamed_output_listinclude_namesinclude_typesinclude_tagsexclude_namesexclude_typesexclude_tagsr9  Literal[True]r:  r;  Sequence[str] | Noner<  r=  r>  r?  r@  AsyncIterator[RunLogPatch]c                   d S r   r$   r   r	  r   r9  r:  r;  r<  r=  r>  r?  r@  r    s               r%   astream_logz_ConfigurableModel.astream_log  s	      &)Sr'   )r:  r;  r<  r=  r>  r?  r@  Literal[False]AsyncIterator[RunLog]c                   d S r   r$   rE  s               r%   rF  z_ConfigurableModel.astream_log  s	      !$r'   2AsyncIterator[RunLogPatch] | AsyncIterator[RunLog]c              |   K    |                      |          j        |f|||||||
|	|d	|2 3 d {V }|W V  6 d S )N)	r   r9  r:  r;  r<  r=  r@  r?  r>  )r   rF  )r   r	  r   r9  r:  r;  r<  r=  r>  r?  r@  r    r  s                r%   rF  z_ConfigurableModel.astream_log  s        7t{{6**6
&?''%%''
 
 
 
 	 	 	 	 	 	 	! GGGGG
 
 
s   ;v2)versionr;  r<  r=  r>  r?  r@  rM  Literal['v1', 'v2']AsyncIterator[StreamEvent]c              z   K    |                      |          j        |f||||||	||d|
2 3 d {V }|W V  6 d S )N)r   rM  r;  r<  r=  r@  r?  r>  )r   astream_events)r   r	  r   rM  r;  r<  r=  r>  r?  r@  r    r  s               r%   rQ  z!_ConfigurableModel.astream_events  s       :t{{6**9
''%%''
 
 
 
 	 	 	 	 	 	 	! GGGGG
 
 
s   :toolsJSequence[dict[str, Any] | type[BaseModel] | Callable[..., Any] | BaseTool]'Runnable[LanguageModelInput, AIMessage]c                :     |                      d          |fi |S )Nr   r   )r   rR  r    s      r%   r   z_ConfigurableModel.bind_tools  s*    
 .t--e>>v>>>r'   schema dict[str, Any] | type[BaseModel]8Runnable[LanguageModelInput, dict[str, Any] | BaseModel]c                :     |                      d          |fi |S )Nr   rV  )r   rW  r    s      r%   r   z)_ConfigurableModel.with_structured_output  s+    
 :t 899&KKFKKKr'   )
r   r   r   r   r   ru   r   r   r!   r   )r   ru   r!   r   r   )r   r   r!   r   )r   r   r!   r   )r   r   r    r   r!   r   )r!   r   )r	  r   r   r   r    r   r!   r   )r	  r   r   r   r    r  r!   r  )r	  r   r   r   r    r  r!   r  )
r  r  r   r  r  r  r    r  r!   r  )
r  r*  r   r+  r  r  r    r   r!   r,  )
r  r*  r   r+  r  r  r    r   r!   r0  )r	  r3  r   r   r    r  r!   r  )r	  r6  r   r   r    r  r!   r  )r	  r   r   r   r9  rA  r:  r  r;  rB  r<  rB  r=  rB  r>  rB  r?  rB  r@  rB  r    r   r!   rC  )r	  r   r   r   r9  rG  r:  r  r;  rB  r<  rB  r=  rB  r>  rB  r?  rB  r@  rB  r    r   r!   rH  )r	  r   r   r   r9  r  r:  r  r;  rB  r<  rB  r=  rB  r>  rB  r?  rB  r@  rB  r    r   r!   rJ  )r	  r   r   r   rM  rN  r;  rB  r<  rB  r=  rB  r>  rB  r?  rB  r@  rB  r    r   r!   rO  )rR  rS  r    r   r!   rT  )rW  rX  r    r   r!   rY  )r   
__module____qualname__r   r   r   r   r  propertyr   r  r  r  r  r  r$  r)  r/  r2  r5  r8  r	   rF  rQ  r   r   __classcell__)r'  s   @r%   r   r   _  sE        15LQ_a
 
 
 
 
 
." " " "<    	 	 	 	 )-
 
 
 
 
B T T T X XT  )-J J J J XJ  )-Q Q Q Q XQ  )-N N N N XN  )-    X @D

 #(
 
 
 
 
 
 
 
> @D

 #(
 
 
 
 
 
 
 
> DH
 #(       @ DH
 #(       B  )-Q Q Q Q XQ  )-    X  )-)
 #*..2.2-1.2.2-1) ) ) ) ) X X)   )-$ +/.2.2-1.2.2-1$ $ $ $ $ X X$   )-
 *..2.2-1.2.2-1     X<  )-
 (,.2.2-1.2.2-1     X:? ? ? ?L L L L L L L Lr'   )r   r   r    r   r!   r
   )rt   ru   rv   ru   r!   r   )r   ru   r!   r   )rS   ru   r   r   r   r   r   r   r    r   r!   r
   r   )rS   r   r   r   r   r   r   r   r    r   r!   r   )rS   r   r   r   r   r   r   r   r    r   r!   r   )rS   r   r   r   r   r   r   r   r    r   r!   r   )rS   ru   r   r   r    r   r!   r
   )r   ru   r!   r   )rS   ru   r   r   r!   r   )r   ru   r   ru   r!   ru   ):__doc__
__future__r   r   r   r   typingr   r   r   r   r   r	   langchain_core.language_modelsr
   r   langchain_core.messagesr   r   langchain_core.prompt_valuesr   r   langchain_core.runnablesr   r   r   typing_extensionsr   collections.abcr   r   r   r   typesr   langchain_core.runnables.schemar   langchain_core.toolsr   langchain_core.tracersr   r   pydanticr   r&   rs   __annotations__r   	lru_cacher#  r   r   r   r   r   r   r   r   r$   r'   r%   <module>ro     s   ( ( ( " " " " " "                         M L L L L L L L 9 9 9 9 9 9 9 9 S S S S S S S S L L L L L L L L L L & & & & & & #KKKKKKKKKKKK      ;;;;;;------::::::::""""""   
%P'%@%P/+A5I%P 13PRWX%P '):EB	%P
 6%P *?G%P !<7%P %~u=%P '%@%P 0 %P -/GO%P  3^UK!%P" z51#%P$ PP%%P. 
BB/%P8 '%@9%P: .eD;%P< "<7!<7)+;UC)+;UC%~u=#]E:Y.I%P %P %P  % % % %L2& & & &6 SS!344555(4 (4 (4 65(4V 
 "& $ $     
 
 "& $ $     
 
 "&HK $     
 X "&OS $X X X X X X| "&/ / / / / /@ @ @ @F! ! ! !>" " " " @ NL NL NL NL NL"4c"9: NL NL NL NL NLr'   