
    h                    (   d dl mZ d dlZd dlmZ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 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)m*Z* g dZ+edddd	 	 	 	 	 	 	 	 	 	 	 d!d       Z,e	 d"dddd	 	 	 	 	 	 	 	 	 	 	 d#d       Z,e	 d"dddd	 	 	 	 	 	 	 	 	 	 	 d$d       Z,	 d"dddd	 	 	 	 	 	 	 	 	 	 	 d%dZ,dd	 	 	 	 	 	 	 d&dZ-h dZ.d'dZ/d(dZ0ddd)dZ1d*dZ2dZ3 G d  deee
f         Z4y)+    )annotationsN)AsyncIteratorIteratorSequence)util)AnyCallableLiteralOptionalUnioncastoverload)BaseChatModelLanguageModelInputSimpleChatModel)agenerate_from_streamgenerate_from_stream)
AnyMessageBaseMessage)RunnableRunnableConfigensure_config)StreamEvent)BaseTool)RunLogRunLogPatch)	BaseModel)	TypeAliasoverride)r   r   r   r   init_chat_model)model_providerconfigurable_fieldsconfig_prefixc                    y N modelr!   r"   r#   kwargss        X/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain/chat_models/base.pyr    r    +   s         _ConfigurableModelc                    y r%   r&   r'   s        r*   r    r    6        r+   .c                    y r%   r&   r'   s        r*   r    r    A   r.   r+   c                   | s|sd}|xs d}|r|st        j                  d|dd       |st        t        t        |       fd|i|S | r| |d<   |r||d<   t        |||	      S )
a'  Initialize a ChatModel in a single line using the model's name and provider.

    .. note::
        Must have the integration package corresponding to the model provider installed.
        You should look at the `provider integration's API reference <https://python.langchain.com/api_reference/reference.html#integrations>`__
        to see what parameters are supported by the model.

    Args:
        model: The name of the model, e.g. ``'o3-mini'``, ``'claude-3-5-sonnet-latest'``. You can
            also specify model and model provider in a single argument using
            ``'{model_provider}:{model}'`` format, e.g. ``'openai:o1'``.
        model_provider: The model provider if not specified as part of model arg (see
            above). Supported model_provider values and the corresponding integration
            package are:

            - ``openai``              -> ``langchain-openai``
            - ``anthropic``           -> ``langchain-anthropic``
            - ``azure_openai``        -> ``langchain-openai``
            - ``azure_ai``            -> ``langchain-azure-ai``
            - ``google_vertexai``     -> ``langchain-google-vertexai``
            - ``google_genai``        -> ``langchain-google-genai``
            - ``bedrock``             -> ``langchain-aws``
            - ``bedrock_converse``    -> ``langchain-aws``
            - ``cohere``              -> ``langchain-cohere``
            - ``fireworks``           -> ``langchain-fireworks``
            - ``together``            -> ``langchain-together``
            - ``mistralai``           -> ``langchain-mistralai``
            - ``huggingface``         -> ``langchain-huggingface``
            - ``groq``                -> ``langchain-groq``
            - ``ollama``              -> ``langchain-ollama``
            - ``google_anthropic_vertex``    -> ``langchain-google-vertexai``
            - ``deepseek``            -> ``langchain-deepseek``
            - ``ibm``                 -> ``langchain-ibm``
            - ``nvidia``              -> ``langchain-nvidia-ai-endpoints``
            - ``xai``                 -> ``langchain-xai``
            - ``perplexity``          -> ``langchain-perplexity``

            Will attempt to infer model_provider from model if not specified. The
            following providers will be inferred based on these model prefixes:

            - ``gpt-3...`` | ``gpt-4...`` | ``o1...`` -> ``openai``
            - ``claude...``                       -> ``anthropic``
            - ``amazon...``                       -> ``bedrock``
            - ``gemini...``                       -> ``google_vertexai``
            - ``command...``                      -> ``cohere``
            - ``accounts/fireworks...``           -> ``fireworks``
            - ``mistral...``                      -> ``mistralai``
            - ``deepseek...``                     -> ``deepseek``
            - ``grok...``                         -> ``xai``
            - ``sonar...``                        -> ``perplexity``
        configurable_fields: Which model parameters are configurable:

            - None: No configurable fields.
            - ``'any'``: All fields are configurable. **See Security Note below.**
            - Union[List[str], Tuple[str, ...]]: Specified fields are configurable.

            Fields are assumed to have config_prefix stripped if there is a
            config_prefix. If model is specified, then defaults to None. If model is
            not specified, then defaults to ``("model", "model_provider")``.

            ***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: If ``'config_prefix'`` is a non-empty string then model will be
            configurable at runtime via the
            ``config["configurable"]["{config_prefix}_{param}"]`` keys. If
            ``'config_prefix'`` is an empty string then model will be configurable via
            ``config["configurable"]["{param}"]``.
        temperature: Model temperature.
        max_tokens: Max output tokens.
        timeout: The maximum time (in seconds) to wait for a response from the model
            before canceling the request.
        max_retries: The maximum number of attempts the system will make to resend a
            request if it fails due to issues like network timeouts or rate limits.
        base_url: The URL of the API endpoint where requests are sent.
        rate_limiter: A ``BaseRateLimiter`` to space out requests to avoid exceeding
            rate limits.
        kwargs: Additional model-specific keyword args to pass to
            ``<<selected ChatModel>>.__init__(model=model_name, **kwargs)``.

    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.

    .. dropdown:: Init non-configurable model
        :open:

        .. code-block:: 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-3-5-sonnet-latest", temperature=0)
            gemini_2_flash = init_chat_model("google_vertexai:gemini-2.0-flash", temperature=0)

            o3_mini.invoke("what's your name")
            claude_sonnet.invoke("what's your name")
            gemini_2_flash.invoke("what's your name")


    .. dropdown:: Partially configurable model with no default

        .. code-block:: 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"}}
            )
            # GPT-4o response

            configurable_model.invoke(
                "what's your name",
                config={"configurable": {"model": "claude-3-5-sonnet-latest"}}
            )
            # claude-3.5 sonnet response

    .. dropdown:: Fully configurable model with a default

        .. code-block:: 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

            configurable_model_with_default.invoke(
                "what's your name",
                config={
                    "configurable": {
                        "foo_model": "anthropic:claude-3-5-sonnet-20240620",
                        "foo_temperature": 0.6
                    }
                }
            )
            # Claude-3.5 sonnet response with temperature 0.6

    .. dropdown:: Bind tools to a configurable model

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

        .. code-block:: 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?"
            )
            # GPT-4o response with tool calls

            configurable_model_with_tools.invoke(
                "Which city is hotter today and which is bigger: LA or NY?",
                config={"configurable": {"model": "claude-3-5-sonnet-20240620"}}
            )
            # Claude-3.5 sonnet response with tools

    .. versionadded:: 0.2.7

    .. versionchanged:: 0.2.8

        Support for ``configurable_fields`` and ``config_prefix`` added.

    .. versionchanged:: 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").

    .. versionchanged:: 0.3.5

        Out of beta.

    .. versionchanged:: 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(   )default_configr#   r"   )warningswarn_init_chat_model_helperr   strr,   r'   s        r*   r    r    O   s    R ,9!'RM0}   		
 &e
)
 
 	

 w#1 #/ r+   )r!   c               0   t        | |      \  } }|dk(  rt        d       ddlm}  |dFd| i|S |dk(  rt        d       ddlm}  |dFd| i|S |d	k(  rt        d       dd
lm}  |dFd| i|S |dk(  rt        d       ddlm}  |dFd| i|S |dk(  rt        d       ddl	m
}  |dFd| i|S |dk(  rt        d       ddlm}  |dFd| i|S |dk(  rt        d       ddlm}	  |	dFd| i|S |dk(  rt        d       ddlm}
  |
dFd| i|S |dk(  r	 t        d       ddlm}  dFd| i|S |dk(  rt        d       dd lm}  |dFd| i|S |d!k(  rt        d"       dd#lm}  |dFd| i|S |d$k(  rt        d%       dd&lm}  |dFd'| i|S |d(k(  rt        d)       dd*lm}  |dFd| i|S |d+k(  rt        d,       dd-lm}  |dFd'| i|S |d.k(  rt        d,       dd/lm}  |dFd| i|S |d0k(  rt        d       dd1l m!}  |dFd| i|S |d2k(  rt        d3d45       dd6l"m#}  |dFd| i|S |d7k(  rt        d8       dd9l$m%}  |dFd| i|S |d:k(  rt        d;       dd<l&m'}  |dFd'| i|S |d=k(  rt        d>       dd?l(m)}  |dFd| i|S |d@k(  rt        dA       ddBl*m+}  |dFd| i|S dCjY                  tZ              }dD|dE| }t]        |      # t&        $ r1 	 t        d       ddlm} n# t&        $ r t        d       Y nw xY wY w xY w)GNopenailangchain_openair   )
ChatOpenAIr(   	anthropiclangchain_anthropic)ChatAnthropicazure_openai)AzureChatOpenAIazure_ailangchain_azure_ai)AzureAIChatCompletionsModelcoherelangchain_cohere)
ChatCoheregoogle_vertexailangchain_google_vertexai)ChatVertexAIgoogle_genailangchain_google_genai)ChatGoogleGenerativeAI	fireworkslangchain_fireworks)ChatFireworksollamalangchain_ollama)
ChatOllamalangchain_communitytogetherlangchain_together)ChatTogether	mistralailangchain_mistralai)ChatMistralAIhuggingfacelangchain_huggingface)ChatHuggingFacemodel_idgroqlangchain_groq)ChatGroqbedrocklangchain_aws)ChatBedrockbedrock_converse)ChatBedrockConversegoogle_anthropic_vertex)ChatAnthropicVertexdeepseeklangchain_deepseekzlangchain-deepseek	pkg_kebab)ChatDeepSeeknvidialangchain_nvidia_ai_endpoints)
ChatNVIDIAibmlangchain_ibm)ChatWatsonxxailangchain_xai)ChatXAI
perplexitylangchain_perplexity)ChatPerplexityz, zUnsupported model_provider=z".

Supported model providers are: r&   )/_parse_model
_check_pkgr;   r<   r>   r?   rA   langchain_azure_ai.chat_modelsrD   rF   rG   rI   rJ   rL   rM   rO   rP   rR   rS   ImportErrorlangchain_community.chat_modelsrV   rW   rY   rZ   r\   r]   r`   ra   rc   rd   rf   &langchain_google_vertexai.model_gardenrh   rj   rm   ro   rp   rr   rs   ru   rv   rx   ry   join_SUPPORTED_PROVIDERS
ValueError)r(   r!   r)   r<   r?   rA   rD   rG   rJ   rM   rP   rS   rW   rZ   r]   ra   rd   rf   rh   rm   rp   rs   rv   ry   	supportedmsgs                             r*   r7   r7   T  s    )?E>!%&/0000$()5353F33'%&45U5f55#'(N*AA&AA!%&/0000**./:2%2622'+,A%<E<V<<$()5353F33!	/)*3 0000#'(32%2622$()5353F33&*+98888#$+.e.v.."?#- 4E4V44++?#5"99&9922./N"99&99#'3GH32%2622!23<0000?#-4E4V44?#)-U-f--%)*74E4V44		./I
&~''KI;W  S/Y  	//01F / -./	/s6   K 	L%K76L7LLLLL>   rq   rt   r_   rE   rQ   r:   rb   rB   ri   rU   r=   rN   rX   rw   r[   r@   rK   rH   re   rg   c                t    t         fddD              ry j                  d      ry j                  d      ry j                  d      ry	 j                  d
      ry j                  d      ry j                  d      ry j                  d      ry j                  d      ry j                  d      ryy )Nc              3  @   K   | ]  }j                  |        y wr%   )
startswith).0pre
model_names     r*   	<genexpr>z0_attempt_infer_model_provider.<locals>.<genexpr>  s     
P#:  %
Ps   )zgpt-3zgpt-4o1o3r:   clauder=   commandrE   zaccounts/fireworksrN   geminirH   zamazon.rb   mistralrX   ri   grokrt   sonarrw   )anyr   )r   s   `r*   _attempt_infer_model_providerr     s    

P1O
PPX&Y'12X& Y'Y'Z(V$W%r+   c                <   |sUd| v rQ| j                  d      d   t        v r7| j                  d      d   }dj                  | j                  d      dd        } |xs t        |       }|sd| d}t	        |      |j                  dd      j                         }| |fS )N:r      z)Unable to infer model provider for model=z), please specify model_provider directly.-_)splitr   r   r   r   replacelower)r(   r!   r   s      r*   rz   rz     s    5LKKQ#77S)!,S)!"-.#K'DU'KN8% :' ( 	 o#++C5;;=N.  r+   rk   c                   t        j                  |       s*||n| j                  dd      }d|  d| d}t        |      y )Nr   r   zUnable to import z&. Please install with `pip install -U `)r   	find_specr   r}   )pkgrl   r   s      r*   r{   r{     sP    >>#!*!6ICKKS<Q	u$J9+UVW 	 # r+   c                D    | j                  |      r| t        |      d  } | S r%   )r   len)sprefixs     r*   _remove_prefixr   "  s#    ||Fc&kmHr+   )
bind_toolswith_structured_outputc                  t    e Zd Zddddd	 	 	 	 	 	 	 	 	 d#dZd$dZd%d&dZd'd	Z	 d%	 	 	 	 	 d(d
Zed)d       Z	e
	 d%	 	 	 	 	 	 	 d*d       Ze
	 d%	 	 	 	 	 	 	 d*d       Ze
	 d%	 	 	 	 	 	 	 d+d       Ze
	 d%	 	 	 	 	 	 	 d,d       Z	 d%dd	 	 	 	 	 	 	 	 	 d- fdZ	 d%dd	 	 	 	 	 	 	 	 	 d- fdZ	 d%dd	 	 	 	 	 	 	 	 	 d. fdZ	 d%dd	 	 	 	 	 	 	 	 	 d/ fdZe
	 d%	 	 	 	 	 	 	 d0d       Ze
	 d%	 	 	 	 	 	 	 d1d       Ze	 d%ddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d       Ze	 d%dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3d       Ze
	 d%ddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d       Ze
	 d%dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d        Z	 	 	 	 	 	 d6d!Z	 	 	 	 	 	 d7d"Z xZS )8r,   Nr   r1   r&   r4   r"   r#   queued_declarative_operationsc                   |xs i | _         |dk(  r|n
t        |      | _        |r|j                  d      s|dz   n|| _        t        |      | _        y )Nr   r   )_default_configlist_configurable_fieldsendswith_config_prefix_queued_declarative_operations)selfr4   r"   r#   r   s        r*   __init__z_ConfigurableModel.__init__,  sm     &4%9r #e+  )* 	! ]%;%;C%@ C 	
 NR)N
+r+   c                     t         v r	d fd}|S  j                  r* j                         x}rt        |      rt	        |      S  d} j                  r|dz  }|dz  }t        |      )Nc                     t        j                        }|j                  | |f       t        t	        j
                        t        j                  t               rt        j                        nj                  j                  |      S )Nr   )	r   r   appendr,   dictr   
isinstancer   r   )argsr)   r   namer   s      r*   queuez-_ConfigurableModel.__getattr__.<locals>.queueJ  s~    04771- .44dD&5IJ)#'(<(<#=!$";";TB )-T-F-F(G22"&"5"52O r+   z! is not a BaseChatModel attributez, and is not implemented on the default model.)r   r   r)   r   returnr,   )_DECLARATIVE_METHODSr   _modelhasattrgetattrAttributeError)r   r   r   r(   r   s   ``   r*   __getattr__z_ConfigurableModel.__getattr__C  s}    '' Ldkkm%;U%;PTAU5$''78AACs
S!!r+   c                    i | j                   | j                  |      }t        di |}| j                  D ]  \  }}} t	        ||      |i |} |S )Nr&   )r   _model_paramsr7   r   r   )r   configparamsr(   r   r   r)   s          r*   r   z_ConfigurableModel._modela  sh    GD((GD,>,>v,FG'1&1"&"E"E 	:D$(GE4($9&9E	:r+   c                z   t        |      }|j                  di       j                         D ci c]7  \  }}|j                  | j                        rt        || j                        |9 }}}| j                  dk7  r2|j                         D ci c]  \  }}|| j                  v s|| }}}|S c c}}w c c}}w )Nconfigurabler   )r   getitemsr   r   r   r   )r   r   kvmodel_paramss        r*   r   z _ConfigurableModel._model_paramsh  s    v& 

>26<<>
1||D//0 1d112A5
 

 $$-!-!3!3!5Ad>W>W9W1L  
s   <B1B7'B7c                   t        di |xs i t        t         |      }| j                  |      }|j                         D ci c]  \  }}|dk7  s|| }}}|j	                  di       j                         D ci c]   \  }}t        || j                        |vr||" c}}|d<   t        | j                        }|r|j                  ddd|if       t        i | j                  |t        | j                  t              rt        | j                        n| j                  | j                  |      S c c}}w c c}}w )z4Bind config to a Runnable, returning a new Runnable.r   with_configr&   r   r   )r   r   r   r   r   r   r   r   r   r   r,   r   r   r   )r   r   r)   r   r   r   remaining_configr   s           r*   r   z_ConfigurableModel.with_configu  sE     Q6<RQD4PQ))&1-3\\^STQqN?RAqDSS 

>26<<>,
1a!4!45\I qD,
(
 )-T-P-P(Q%)00!/0 "Cd22ClC$33T: !%T%>%> ?**--*G
 	
 T,
s   D6D6=%D<c                Z    ddl m}m} t        t        t        ||f   t
        t           f   S )z%Get the input type for this runnable.r   )ChatPromptValueConcreteStringPromptValue)langchain_core.prompt_valuesr   r   r   r8   r   r   )r   r   r   s      r*   	InputTypez_ConfigurableModel.InputType  s5    	
 #%<<=
 	
r+   c                J     | j                  |      j                  |fd|i|S Nr   )r   invoker   inputr   r)   s       r*   r   z_ConfigurableModel.invoke  s*     *t{{6"))%II&IIr+   c                f   K    | j                  |      j                  |fd|i| d {   S 7 wr   )r   ainvoker   s       r*   r   z_ConfigurableModel.ainvoke  s4      1T[[(00PvPPPPPs   (1/1c              +  h   K    | j                  |      j                  |fd|i|E d {    y 7 wr   )r   streamr   s       r*   r   z_ConfigurableModel.stream  s1      .4;;v&--eMFMfMMM   (202c               x   K    | j                  |      j                  |fd|i|2 3 d {   }| 7 
6 y wr   )r   astreamr   r   r   r)   xs        r*   r   z_ConfigurableModel.astream  sE      3t{{6*225RR6R 	 	!G	R   %:868:8:F)return_exceptionsc                   |xs d }|t        |t              st        |      dk  r:t        |t              r|d   } | j	                  |      j
                  |f||d|S t        |   |f||d|S Nr   r   )r   r   )r   r   r   r   r   batchsuperr   inputsr   r   r)   	__class__s        r*   r   z_ConfigurableModel.batch  s     4>Z5V9I&$',4;;v&,,"3 	  w}
/
 	
 	
r+   c                 K   |xs d }|t        |t              st        |      dk  rBt        |t              r|d   } | j	                  |      j
                  |f||d| d {   S t        |   |f||d| d {   S 7 7 wr   )r   r   r   r   r   abatchr   r   s        r*   r   z_ConfigurableModel.abatch  s      4>Z5V9I&$'3V,33"3 	   W^
/
 	
 
 	

s$   A$B'B(BB	B	Bc             +  :  K   |xs d }|t        |t              st        |      dk  rQt        |t              r|d   } | j	                  t        t        |            j                  |f||d|E d {    y t        |   |f||d|E d {    y 7 !7 wr   )	r   r   r   r   r   r   r   batch_as_completedr   r   s        r*   r   z%_ConfigurableModel.batch_as_completed  s      4>Z5V9I&$'St{{4#?@SS"3 	   w1"3 	  s$   A2B5B6BBBBc              Z  K   |xs d }|t        |t              st        |      dk  rWt        |t              r|d   } | j	                  t        t        |            j                  |f||d|2 3 d {   }| t        |   |f||d|2 3 d {   }| 7 ,6 y 7 6 y wr   )	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   s      4>Z5V9I&$'"4;;^V,!! "3   a  !76"3 	  a %  sN   A/B+2B%6B#7B%:B+B)B'B)B+#B%%B+'B))B+c              +  h   K    | j                  |      j                  |fd|i|E d {    y 7 wr   )r   	transformr   s       r*   r   z_ConfigurableModel.transformA  s1      14;;v&00PvPPPPr   c               x   K    | j                  |      j                  |fd|i|2 3 d {   }| 7 
6 y wr   )r   
atransformr   s        r*   r   z_ConfigurableModel.atransformJ  sE      6t{{6*55eUFUfU 	 	!G	Ur   T)diffwith_streamed_output_listinclude_namesinclude_typesinclude_tagsexclude_namesexclude_typesexclude_tagsc                    y r%   r&   r   r   r   r   r   r   r   r   r   r   r   r)   s               r*   astream_logz_ConfigurableModel.astream_logT  s     &)r+   )r   r   r   r   r   r   r   c                    y r%   r&   r  s               r*   r  z_ConfigurableModel.astream_loge  s     !$r+   c                 K    | j                  |      j                  |f|||||||
|	|d	|2 3 d {   }| 7 
6 y w)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_logv  sl       7t{{6*66
&?''%%''
 
 	 	! G	 
s#   -AA >A AA  Av2)versionr   r   r   r   r   r   c                 K    | j                  |      j                  |f||||||	||d|
2 3 d {   }| 7 
6 y w)N)r   r  r   r   r   r   r   r   )r   astream_events)r   r   r   r  r   r   r   r   r   r   r)   r   s               r*   r	  z!_ConfigurableModel.astream_events  si      :t{{6*99
''%%''
 
 	 	! G	 
s   ,A?=?A?Ac                2     | j                  d      |fi |S )Nr   r   )r   toolsr)   s      r*   r   z_ConfigurableModel.bind_tools  s!    
 .t-e>v>>r+   c                2     | j                  d      |fi |S )Nr   r  )r   schemar)   s      r*   r   z)_ConfigurableModel.with_structured_output  s"    
 :t 89&KFKKr+   )
r4   zOptional[dict]r"   1Union[Literal['any'], list[str], tuple[str, ...]]r#   r8   r   z!Sequence[tuple[str, tuple, dict]]r   None)r   r8   r   r   r%   )r   Optional[RunnableConfig]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)   Optional[Any]r   Iterator[Any])r   r   r   r  r)   r  r   AsyncIterator[Any])
r   zlist[LanguageModelInput]r   z5Optional[Union[RunnableConfig, list[RunnableConfig]]]r   boolr)   r  r   z	list[Any])
r   Sequence[LanguageModelInput]r   9Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]r   r  r)   r   r   z+Iterator[tuple[int, Union[Any, Exception]]])
r   r  r   r  r   r  r)   r   r   zAsyncIterator[tuple[int, Any]])r   zIterator[LanguageModelInput]r   r  r)   r  r   r  )r   z!AsyncIterator[LanguageModelInput]r   r  r)   r  r   r  )r   r   r   r  r   zLiteral[True]r   r  r   Optional[Sequence[str]]r   r  r   r  r   r  r   r  r   r  r)   r   r   zAsyncIterator[RunLogPatch])r   r   r   r  r   zLiteral[False]r   r  r   r  r   r  r   r  r   r  r   r  r   r  r)   r   r   zAsyncIterator[RunLog])r   r   r   r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  r   r  r)   r   r   z8Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]])r   r   r   r  r  zLiteral['v1', 'v2']r   r  r   r  r   r  r   r  r   r  r   r  r)   r   r   zAsyncIterator[StreamEvent])r  zDSequence[Union[dict[str, Any], type[BaseModel], Callable, BaseTool]]r)   r   r   z)Runnable[LanguageModelInput, BaseMessage])r  zUnion[dict, type[BaseModel]]r)   r   r   z4Runnable[LanguageModelInput, Union[dict, BaseModel]])__name__
__module____qualname__r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r   r   __classcell__)r   s   @r*   r,   r,   +  s3    *.QVKM
 '
 O	

 
 (I
 

."< ,0
(
 
 
	
@ 
 
   ,0J!J )J 	J
 
J J  ,0Q!Q )Q 	Q
 
Q Q  ,0N!N )N  	N
 
N N  ,0! )  	
 
  IM

 #(
(
 F

  
  
 

> IM

 #(
(
 F

  
  
 

> MQ
 #(, J
    
5@ MQ
 #(, J
    
(B  ,0Q+Q )Q  	Q
 
Q Q  ,00 )  	
 
   ,0)
 #*.151504151504)) ))
 ) $() /) /) .) /) /) .) ) 
$) )   ,0$ +/151504151504$$ )$
 $ $($ /$ /$ .$ /$ /$ .$ $ 
$ $   ,0
 *.151504151504 )
  $( / / . / / .  
B <  ,0
 (,151504151504 )
 % / / . / / .  
$ :?S? ? 
3	?L,L L 
>	Lr+   )r(   r8   r!   Optional[str]r"   Literal[None]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"   z;Optional[Union[Literal['any'], list[str], tuple[str, ...]]]r#   r  r)   r   r   z(Union[BaseChatModel, _ConfigurableModel])r(   r8   r!   r  r)   r   r   r   )r   r8   r   r  )r(   r8   r!   r  r   ztuple[str, str])r   r8   rl   r  r   r  )r   r8   r   r8   r   r8   )5
__future__r   r5   collections.abcr   r   r   	importlibr   typingr   r	   r
   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   r   __all__r    r7   r   r   rz   r{   r   r   r,   r&   r+   r*   <module>r.     sI   "  = =    
 < L L 7 ) 6  1 
 %))-#' " '	
 !   
 
 %))-#' " '	
 !   
 
 %)MP#' " K	
 !   
  B %) 	#'BB "B	B !B B .BP %) " 	
 D 00!& 8<  @ UL"4c"9: ULr+   