
    m
i                       d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
mZmZmZmZmZ d dl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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l'm(Z( g dZ)eddddd3d            Z*e	 d4ddddd5d            Z*e	 d4ddddd6d!            Z*	 d4ddddd7d$Z*dd%d8d&Z+h d'Z,d9d)Z-d:d+Z.dd,d;d0Z/d1Z0 G d2 deeef                   Z1dS )<    )annotationsN)AsyncIteratorCallableIteratorSequence)util)AnyLiteral	TypeAliascastoverload)BaseChatModelLanguageModelInputSimpleChatModel)agenerate_from_streamgenerate_from_stream)	AIMessage
AnyMessage)RunnableRunnableConfigensure_config)StreamEvent)BaseTool)RunLogRunLogPatch)	BaseModel)override)r   r   r   r   init_chat_model)model_providerconfigurable_fieldsconfig_prefixmodelstrr   
str | Noner    Noner!   kwargsr	   returnr   c                   d S N r"   r   r    r!   r&   s        C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langchain_classic/chat_models/base.pyr   r   #   s	     C    _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   9   r0   r-   3Literal['any'] | list[str] | tuple[str, ...] | None"BaseChatModel | _ConfigurableModelc                   | 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1  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 back 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
        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 name or ID of the model, e.g. `'o3-mini'`, `'claude-sonnet-4-5-20250929'`.

            You can also specify model and model provider in a single argument using
            `'{model_provider}:{model}'` format, e.g. `'openai:o1'`.

            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`
        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)
            - `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)
            - `perplexity`              -> [`langchain-perplexity`](https://docs.langchain.com/oss/python/integrations/providers/perplexity)
        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`][langchain_core.language_models.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_classic.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_classic.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_classic.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_classic.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
        ```

    !!! warning "Behavior changed in `langchain` 0.2.8"

        Support for `configurable_fields` and `config_prefix` added.

    !!! warning "Behavior changed in `langchain` 0.2.12"

        Support for Ollama via langchain-ollama package added
        (`langchain_ollama.ChatOllama`). Previously,
        the now-deprecated langchain-community version of Ollama was imported
        (`langchain_community.chat_models.ChatOllama`).

        Support for AWS Bedrock models via the Converse API added
        (`model_provider="bedrock_converse"`).

    !!! warning "Behavior changed in `langchain` 0.3.5"

        Out of beta.

    !!! warning "Behavior changed in `langchain` 0.3.19"

        Support for Deepseek, IBM, Nvidia, and xAI models added.

    )r"   r    zconfig_prefix=z has been set but no fields are configurable. Set `configurable_fields=(...)` to specify the model params that are configurable.   )
stacklevelr#   r   r"   )default_configr!   r    )warningswarn_init_chat_model_helperr   r.   r+   s        r,   r   r   G   s    b  :, :9!'RM 
0 
}    		
 	
 	
 	
  
&
 
)
 
 
 	

   w 2#1 #/   r-   )r   c                  t          | |          \  } }|dk    r t          dd           ddlm}  |d_d| i|S |dk    r t          dd	           dd
lm}  |d_d| i|S |dk    r t          dd           ddlm}  |d_d| i|S |dk    r t          dd           ddlm}  |d_d| i|S |dk    r t          dd           ddl	m
}  |d_d| i|S |dk    r t          dd           ddlm}  |d_d| i|S |dk    r t          dd           ddlm}	  |	d_d| i|S |dk    r t          dd            dd!lm}
  |
d_d| i|S |d"k    rj	 t          d#d$           dd%lm} nH# t&          $ r; 	 t          d&d$           dd%lm} n # t&          $ r t          d#d$           Y nw xY wY nw xY w |d_d| i|S |d'k    r t          d(d)           dd*lm}  |d_d| i|S |d+k    r t          d,d-           dd.lm}  |d_d| i|S |d/k    r%t          d0d1           dd2lm}  |j        d_d3| i|S |d4k    r t          d5d6           dd7lm}  |d_d| i|S |d8k    r t          d9d:           dd;lm}  |d_d3| i|S |d<k    r t          d9d=           dd>lm }  |d_d| i|S |d?k    r t          dd@           ddAl!m"}  |d_d| i|S |dBk    r"t          dCdDdEF           ddGl#m$}  |d_d| i|S |dHk    r t          dIdJ           ddKl%m&}  |d_d| i|S |dLk    r t          dMdN           ddOl'm(}  |d_d3| i|S |dPk    r t          dQdR           ddSl)m*}  |d_d| i|S |dTk    r t          dUdV           ddWl+m,}  |d_d| i|S |dXk    r t          dYdZ           dd[l-m.}  |d_d| i|S d\/                    t`                    }d]|d^| }tc          |          )`Nopenailangchain_openai
ChatOpenAIr   )r@   r"   	anthropiclangchain_anthropicChatAnthropic)rC   azure_openaiAzureChatOpenAI)rE   azure_ailangchain_azure_aiAzureAIChatCompletionsModel)rH   coherelangchain_cohere
ChatCohere)rK   google_vertexailangchain_google_vertexaiChatVertexAI)rN   google_genailangchain_google_genaiChatGoogleGenerativeAI)rQ   	fireworkslangchain_fireworksChatFireworks)rT   ollamalangchain_ollama
ChatOllama)rW   langchain_communitytogetherlangchain_togetherChatTogether)r[   	mistralailangchain_mistralaiChatMistralAI)r^   huggingfacelangchain_huggingfaceChatHuggingFace)ra   model_idgroqlangchain_groqChatGroq)re   bedrocklangchain_awsChatBedrock)rh   bedrock_converseChatBedrockConverse)rj   google_anthropic_vertexChatAnthropicVertex)rl   deepseeklangchain_deepseekChatDeepSeekzlangchain-deepseek	pkg_kebab)ro   nvidialangchain_nvidia_ai_endpoints
ChatNVIDIA)rt   ibmlangchain_ibmChatWatsonx)rw   xailangchain_xaiChatXAI)rz   
perplexitylangchain_perplexityChatPerplexity)r}   upstagelangchain_upstageChatUpstage)r   , zUnsupported model_provider=z".

Supported model providers are: r*   )2_parse_model
_check_pkgr?   r@   rB   rC   rE   langchain_azure_ai.chat_modelsrH   rJ   rK   rM   rN   rP   rQ   rS   rT   rV   rW   ImportErrorlangchain_community.chat_modelsrZ   r[   r]   r^   r`   ra   from_model_idrd   re   rg   rh   rj   &langchain_google_vertexai.model_gardenrl   rn   ro   rs   rt   rv   rw   ry   rz   r|   r}   r   r   join_SUPPORTED_PROVIDERS
ValueError)r"   r   r&   r@   rC   rE   rH   rK   rN   rQ   rT   rW   r[   r^   ra   re   rh   rj   rl   ro   rt   rw   rz   r}   r   	supportedmsgs                              r,   r<   r<   t  s1    )??E>!!%|444//////z000000$$(/:::555555}3353F333''%'899944444455U5f555##')FGGGNNNNNN**AAA&AAA!!%|444//////z000000***.???::::::|22%26222''+-EFFFAAAAAA%%<<E<V<<<$$(/:::555555}3353F333!!	=)<8883333333 	= 	= 	==0,???FFFFFFF = = = -|<<<<<=	= z000000##'888333333|22%26222$$(/:::555555}3353F333&&*,=>>>999999,,FFeFvFFF#Z000++++++x..e.v...""?M222------ {44E4V444+++?$9:::555555""999&999222.0EFFFNNNNNN""999&999##'CWXXXX333333|22%26222!!2LAAA<<<<<<z000000?M222------{44E4V444?I...))))))w--U-f---%%)+;<<<777777~44E4V444""&666111111{111&111		.//IW~WWIWW  S//s6   E" "
F'-FF'F!F' F!!F'&F'>   ru   rx   rc   rI   rU   r>   rf   r~   rF   rm   rY   rA   rR   r\   r{   r_   rD   rO   rL   ri   rk   
model_namec                `   |                                  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          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-davincir>   clauderA   commandrI   zaccounts/fireworksrR   geminirL   zamazon.)z
anthropic.zmeta.rf   )mistralmixtralr\   rm   grokrx   sonarr{   solarr~   N)loweranyr   )r   r   s    @r,   _attempt_infer_model_providerr     s    ""$$K  	 	 	 	
	 	 	 	 	 
 x h'' { i(( x 122 { h'' !   Y'' ;+A+A	
, ,  y 455 { j)) z f%% u g&& | g&& y4r-   tuple[str, str]c                   |s@d| v r<|                      dd          \  }}|t          v r|}|} nt          |          }|r|}|} |pt          |           }|s?d                    t	          t                              }d| d| d}t          |          |                    dd                                          }| |fS )	z?Parse model name and provider, inferring provider if necessary.:   r   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/providers-_)splitr   r   r   sortedr   replacer   )r"   r   prefixsuffixinferredsupported_listr   s          r,   r   r   ^  s     	cUllS!,,)))#NEE4V<<H !)#K'DU'K'KN 	6*>#?#?@@L% L L$2L L L 	 oo $++C55;;==N.  r-   rp   pkg
class_namerq   c                   t          j        |           s5||n|                     dd          }d| d| d| d}t          |          d S )Nr   r   zInitializing z requires the z. package. Please install it with `pip install `)r   	find_specr   r   )r   r   rq   r   s       r,   r   r   |  s    ># !*!6IICKKS<Q<Q	@J @ @i @ @3<@ @ @ 	 # 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	 d_d;d;ddddddd<dldH            Z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   r6   r*   r9   r    r!   queued_declarative_operationsr9   dict | Noner    r1   r!   r#   r   !Sequence[tuple[str, tuple, dict]]r'   r%   c                   |pi | _         |dk    r|nt          |          | _        |r|                    d          s|dz   n|| _        t          |          | _        d S )Nr   r   )_default_configlist_configurable_fieldsendswith_config_prefix_queued_declarative_operations)selfr9   r    r!   r   s        r,   __init__z_ConfigurableModel.__init__  s     &4%9r #e++  )** 	! %2%;%;C%@%@MC 	
 NR)N
 N
+++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   
isinstancer   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 model.)r   r	   r&   r	   r'   r.   )_DECLARATIVE_METHODSr   _modelhasattrgetattrAttributeError)r   r   r   r"   r   s   ``   r,   __getattr__z_ConfigurableModel.__getattr__  s    '''       L 	(dkkmm%;U 	(PTAUAU 	(5$'''888 	BAACs
S!!!r-   configRunnableConfig | Noner   c                    i | j         |                     |          }t          di |}| j        D ]\  }}} t	          ||          |i |}|S )Nr*   )r   _model_paramsr<   r   r   )r   r   paramsr"   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-   r   c                     t          |          } fd|                    di                                           D             } j        dk    r  fd|                                D             }|S )Nc                    i | ]:\  }}|                     j                  |                    j                  |;S r*   )r   r   removeprefixr   kvr   s      r,   
<dictcomp>z4_ConfigurableModel._model_params.<locals>.<dictcomp>  sS     
 
 
1||D/00
NN4.//
 
 
r-   configurabler   c                .    i | ]\  }}|j         v ||S r*   )r   r   s      r,   r   z4_ConfigurableModel._model_params.<locals>.<dictcomp>  s3       Ad>W9W9W19W9W9Wr-   )r   getitemsr   )r   r   model_paramss   `  r,   r   z _ConfigurableModel._model_params  s    v&&
 
 
 


>266<<>>
 
 

 $--   !-!3!3!5!5  L r-   r&   c                     t          di |pi t          d|          }                     |          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 )	z8Bind config to a `Runnable`, returning a new `Runnable`.r   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                T    i | ]$\  }}|                     j                  v!||%S r*   )r   r   )r   r   r   r   r   s      r,   r   z2_ConfigurableModel.with_config.<locals>.<dictcomp>  sC     ,
 ,
 ,
1~~d122,FF qFFFr-   r   with_configr*   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  sM     SS6<RSD9I64R4RSS))&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                R    ddl m}m} t          |z  |z  t          t
                   z  S )z'Get the input type for this `Runnable`.r   )ChatPromptValueConcreteStringPromptValue)langchain_core.prompt_valuesr   r   r#   r   r   )r   r   r   s      r,   	InputTypez_ConfigurableModel.InputType  sH    	
 	
 	
 	
 	
 	
 	
 	
 &&)@@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 Nr   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.abatchB  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 Nr   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,   r  z&_ConfigurableModel.abatch_as_completed{  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,   r  z_ConfigurableModel.transform  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,   r  z_ConfigurableModel.atransform  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_tagsr   Literal[True]r!  r"  Sequence[str] | Noner#  r$  r%  r&  r'  AsyncIterator[RunLogPatch]c                   d S r)   r*   r   r   r   r   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*   r,  s               r,   r-  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   r   r!  r"  r#  r$  r'  r&  r%  )r   r-  )r   r   r   r   r!  r"  r#  r$  r%  r&  r'  r&   r   s                r,   r-  z_ConfigurableModel.astream_log  s        7t{{6**6
&?''%%''
 
 
 
 	 	 	 	 	 	 	! GGGGG
 
 
s   ;v2)versionr"  r#  r$  r%  r&  r'  r4  Literal['v1', 'v2']AsyncIterator[StreamEvent]c              z   K    |                      |          j        |f||||||	||d|
2 3 d {V }|W V  6 d S )N)r   r4  r"  r#  r$  r'  r&  r%  )r   astream_events)r   r   r   r4  r"  r#  r$  r%  r&  r'  r&   r   s               r,   r8  z!_ConfigurableModel.astream_events  s       :t{{6**9
''%%''
 
 
 
 	 	 	 	 	 	 	! GGGGG
 
 
s   :tools@Sequence[dict[str, Any] | type[BaseModel] | Callable | BaseTool]'Runnable[LanguageModelInput, AIMessage]c                :     |                      d          |fi |S )Nr   r   )r   r9  r&   s      r,   r   z_ConfigurableModel.bind_tools  s*    
 .t--e>>v>>>r-   schemadict | type[BaseModel].Runnable[LanguageModelInput, dict | BaseModel]c                :     |                      d          |fi |S )Nr   r=  )r   r>  r&   s      r,   r   z)_ConfigurableModel.with_structured_output  s+    
 :t 899&KKFKKKr-   )
r9   r   r    r1   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  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'   r/  )r   r	   r   r   r   r  r!  r  r"  r)  r#  r)  r$  r)  r%  r)  r&  r)  r'  r)  r&   r	   r'   r1  )r   r	   r   r   r4  r5  r"  r)  r#  r)  r$  r)  r%  r)  r&  r)  r'  r)  r&   r	   r'   r6  )r9  r:  r&   r	   r'   r;  )r>  r?  r&   r	   r'   r@  )__name__
__module____qualname__r   r   r   r   r   propertyr   r   r   r   r   r   r  r  r  r  r  r  r   r-  r8  r   r   __classcell__)r  s   @r,   r.   r.     s1        '+LQKM
 
 
 
 
 
." " " "<        )-
 
 
 
 
@ 
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)   )-$ +/.2.2-1.2.2-1$ $ $ $ $ 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%   r!   r$   r&   r	   r'   r   r)   )r"   r%   r   r$   r    r%   r!   r$   r&   r	   r'   r.   )r"   r$   r   r$   r    r1   r!   r$   r&   r	   r'   r.   )r"   r$   r   r$   r    r3   r!   r$   r&   r	   r'   r4   )r"   r#   r   r$   r&   r	   r'   r   )r   r#   r'   r$   )r"   r#   r   r$   r'   r   )r   r#   r   r#   rq   r$   r'   r%   )2
__future__r   r:   collections.abcr   r   r   r   	importlibr   typingr	   r
   r   r   r   langchain_core.language_modelsr   r   r   *langchain_core.language_models.chat_modelsr   r   langchain_core.messagesr   r   langchain_core.runnablesr   r   r   langchain_core.runnables.schemar   langchain_core.toolsr   langchain_core.tracersr   r   pydanticr   typing_extensionsr   __all__r   r<   r   r   r   r   r   r.   r*   r-   r,   <module>rU     sW   " " " " " "  G G G G G G G G G G G G       : : : : : : : : : : : : : :         
        : 9 9 9 9 9 9 9 L L L L L L L L L L 7 7 7 7 7 7 ) ) ) ) ) ) 6 6 6 6 6 6 6 6       & & & & & &   
 "& $ $     
 
 "& $ $     
 
 "&HK $     
 j "&OS $j j j j j j`	 "&F F F F F FR   2E E E EP! ! ! !< FJ       @ RL RL RL RL RL"4c"9: RL RL RL RL RLr-   