a
    •˜ëjÄŒ  ã                
   @  s  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dddddœdd„ƒZ,ed3ddddœdddddddœdd„ƒZ,ed4ddddœdddddddœdd„ƒZ,d5ddddœdddddddœd d„Z,dd!œddddd"œd#d$„Z-h d%£Z.ddd&œd'd(„Z/ddd)d*œd+d,„Z0dd-œdddd.œd/d0„Z1d1Z2G d2d„ deee
f ƒZ3dS )6é    )Ú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_prefixÚstrzOptional[str]ÚNoner   r   )Úmodelr    r!   r"   ÚkwargsÚreturnc                K  s   d S ©N© ©r%   r    r!   r"   r&   r)   r)   úY/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/chat_models/base.pyr   #   s    r   Ú_ConfigurableModelc                K  s   d S r(   r)   r*   r)   r)   r+   r   .   s    .ú1Union[Literal['any'], list[str], tuple[str, ...]]c                K  s   d S r(   r)   r*   r)   r)   r+   r   9   s    z;Optional[Union[Literal['any'], list[str], tuple[str, ...]]]z(Union[BaseChatModel, _ConfigurableModel]c                K  sv   | s|sd}|pd}|r2|s2t jd|›d�dd� |sPttd| ƒfd|i|¤ŽS | r\| |d	< |rh||d< t|||d
�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-...`` | ``o1...`` | ``o3...`` -> ``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.5-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-latest",
                        "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-latest"}},
            )
            # 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    r%   )Údefault_configr"   r!   )ÚwarningsÚwarnÚ_init_chat_model_helperr   r,   r*   r)   r)   r+   r   G   s4     w
üÿþýý)r    )r%   r    r&   r'   c                K  sn  t | |ƒ\} }|dkr<tdƒ ddlm} |f d| i|¤ŽS |dkrjtdƒ ddlm} |f d| i|¤ŽS |d	kr˜tdƒ dd
lm} |f d| i|¤ŽS |dkrÆtdƒ ddlm} |f d| i|¤ŽS |dkrôtdƒ ddl	m
} |f d| i|¤ŽS |dk�r$tdƒ ddlm} |f d| i|¤ŽS |dk�rTtdƒ ddlm}	 |	f d| i|¤ŽS |dk�r„tdƒ ddlm}
 |
f d| i|¤ŽS |dk�rztdƒ ddlm} W nJ t�yð   ztdƒ ddlm} W n t�yê   tdƒ Y n0 Y n0 |f d| i|¤ŽS |dk�r4tdƒ dd lm} |f d| i|¤ŽS |d!k�rdtd"ƒ dd#lm} |f d| i|¤ŽS |d$k�r”td%ƒ dd&lm} |f d'| i|¤ŽS |d(k�rÄtd)ƒ dd*lm} |f d| i|¤ŽS |d+k�rôtd,ƒ dd-lm} |f d'| i|¤ŽS |d.k�r$td,ƒ dd/lm} |f d| i|¤ŽS |d0k�rTtdƒ dd1l m!} |f d| i|¤ŽS |d2k�rˆtd3d4d5� dd6l"m#} |f d| i|¤ŽS |d7k�r¸td8ƒ dd9l$m%} |f d| i|¤ŽS |d:k�rètd;ƒ dd<l&m'} |f d'| i|¤ŽS |d=k�rtd>ƒ dd?l(m)} |f d| i|¤ŽS |d@k�rHtdAƒ ddBl*m+} |f d| i|¤ŽS dC ,t-¡}dD|›dE|› �}t.|ƒ‚d S )FNÚopenaiÚlangchain_openair   )Ú
ChatOpenAIr%   Ú	anthropicÚlangchain_anthropic)ÚChatAnthropicÚazure_openai)ÚAzureChatOpenAIÚazure_aiZ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)Ú
ChatOllamaZlangchain_communityÚtogetherÚlangchain_together)ÚChatTogetherÚ	mistralaiÚlangchain_mistralai)ÚChatMistralAIÚhuggingfaceÚlangchain_huggingface)ÚChatHuggingFaceZmodel_idÚgroqÚlangchain_groq)ÚChatGroqÚbedrockÚlangchain_aws)ÚChatBedrockÚbedrock_converse)ÚChatBedrockConverseÚgoogle_anthropic_vertex)ÚChatAnthropicVertexÚdeepseekÚlangchain_deepseekzlangchain-deepseek©Ú	pkg_kebab)ÚChatDeepSeekZ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: )/Ú_parse_modelÚ
_check_pkgr6   r7   r9   r:   r<   Zlangchain_azure_ai.chat_modelsr>   r@   rA   rC   rD   rF   rG   rI   rJ   rL   rM   ÚImportErrorZlangchain_community.chat_modelsrO   rP   rR   rS   rU   rV   rX   rY   r[   r\   r^   Z&langchain_google_vertexai.model_gardenr`   rb   re   rf   rg   ri   rj   rl   rm   ro   rp   ÚjoinÚ_SUPPORTED_PROVIDERSÚ
ValueError)r%   r    r&   r7   r:   r<   r>   rA   rD   rG   rJ   rM   rP   rS   rV   rY   r\   r^   r`   re   rg   rj   rm   rp   Ú	supportedÚmsgr)   r)   r+   r4   Y  sÀ    
















ÿr4   >   rn   rB   r5   rW   rT   rH   r;   r8   r_   rE   rZ   rK   ra   rk   rN   rQ   r=   r?   rh   r]   )Ú
model_namer'   c                   sœ   t ‡ fdd„dD ƒƒrdS ˆ  d¡r(dS ˆ  d¡r6dS ˆ  d	¡rDd
S ˆ  d¡rRdS ˆ  d¡r`dS ˆ  d¡rndS ˆ  d¡r|dS ˆ  d¡rŠdS ˆ  d¡r˜dS d S )Nc                 3  s   | ]}ˆ   |¡V  qd S r(   )Ú
startswith)Ú.0Úpre©ry   r)   r+   Ú	<genexpr>ô  ó    z0_attempt_infer_model_provider.<locals>.<genexpr>)zgpt-Zo1Zo3r5   Zclauder8   Úcommandr?   zaccounts/fireworksrH   ZgeminirB   zamazon.rZ   ZmistralrQ   ra   Zgrokrk   Zsonarrn   )Úanyrz   r}   r)   r}   r+   Ú_attempt_infer_model_provideró  s*    








r‚   ztuple[str, str])r%   r    r'   c                 C  s€   |sDd| v rD|   d¡d tv rD|   d¡d }d |   d¡dd … ¡} |pNt| ƒ}|shd| ›d�}t|ƒ‚| dd¡ ¡ }| |fS )Nú:r   é   z)Unable to infer model provider for model=z), please specify model_provider directly.ú-Ú_)Úsplitru   rt   r‚   rv   ÚreplaceÚlower)r%   r    rx   r)   r)   r+   rq     s    ÿþý
ÿrq   rc   )Úpkgrd   r'   c                C  s@   t  | ¡s<|d ur|n
|  dd¡}d| › d|› d�}t|ƒ‚d S )Nr†   r…   zUnable to import z&. Please install with `pip install -U ú`)r   Ú	find_specrˆ   rs   )rŠ   rd   rx   r)   r)   r+   rr     s
    
ÿrr   )Ú
bind_toolsÚwith_structured_outputc                      sÈ  e Zd Zdddddœdddd	d
dœdd„Zdddœdd„Zdfdddœdd„Zdddœdd„Zdgddd dœdd„Zee	ddœdd „ƒƒZ
e	dhd!dddd"œd#d$„ƒZe	did!dddd"œd%d&„ƒZe	djd!dd'd(d"œd)d*„ƒZe	dkd!dd'd+d"œd,d-„ƒZdld.d/œd0d1d2d'd3d4œ‡ fd5d6„Zdmd.d/œd0d1d2d'd3d4œ‡ fd7d8„Zdnd.d/œd9d:d2dd;d4œ‡ fd<d=„Zdod.d/œd9d:d2dd>d4œ‡ fd?d@„Ze	dpdAdd'd(d"œdBdC„ƒZe	dqdDdd'd+d"œdEdF„ƒZedrdGdGdddddddHœdddId2dJdJdJdJdJdJddKdLœdMdN„ƒZedsdGdddddddOœdddPd2dJdJdJdJdJdJddQdLœdRdN„ƒZe	dtdGdGdddddddHœddd2d2dJdJdJdJdJdJddSdLœdTdN„ƒZe	dudUdddddddVœdddWdJdJdJdJdJdJddXdYœdZd[„ƒZd\dd]d^œd_d`„Zdaddbdcœddde„Z‡  ZS )vr,   Nr�   r.   r)   ©r1   r!   r"   Úqueued_declarative_operationszOptional[dict]r-   r#   z!Sequence[tuple[str, tuple, dict]]r$   )r1   r!   r"   r�   r'   c                C  sJ   |pi | _ |dkr|nt|ƒ| _|r6| d¡s6|d n|| _t|ƒ| _d S )Nr�   r†   )Ú_default_configÚlistÚ_configurable_fieldsÚendswithÚ_config_prefixÚ_queued_declarative_operations)Úselfr1   r!   r"   r�   r)   r)   r+   Ú__init__+  s    
ÿýÿÿ
ýÿz_ConfigurableModel.__init__r   )Únamer'   c                   sv   ˆ t v r$ddddœ‡ ‡fdd„}|S ˆjrJˆ ¡  }rJt|ˆ ƒrJt|ˆ ƒS ˆ › d�}ˆjrb|d7 }|d7 }t|ƒ‚d S )	Nr   r,   )Úargsr&   r'   c                    sJ   t ˆjƒ}| ˆ | |f¡ ttˆjƒtˆjt ƒr:t ˆjƒnˆjˆj|d�S )Nr�   )	r’   r–   Úappendr,   Údictr‘   Ú
isinstancer“   r•   )rš   r&   r�   ©r™   r—   r)   r+   ÚqueueI  s    ÿ
ÿúz-_ConfigurableModel.__getattr__.<locals>.queuez! is not a BaseChatModel attributez, and is not implemented on the default modelÚ.)Ú_DECLARATIVE_METHODSr‘   Ú_modelÚhasattrÚgetattrÚAttributeError)r—   r™   rŸ   r%   rx   r)   rž   r+   Ú__getattr__B  s    

z_ConfigurableModel.__getattr__zOptional[RunnableConfig]r   )Úconfigr'   c                 C  sL   i | j ¥|  |¡¥}tf i |¤Ž}| jD ]\}}}t||ƒ|i |¤Ž}q(|S r(   )r‘   Ú_model_paramsr4   r–   r¤   )r—   r§   Úparamsr%   r™   rš   r&   r)   r)   r+   r¢   `  s
    z_ConfigurableModel._modelrœ   c                   sJ   t |ƒ}‡ fdd„| di ¡ ¡ D ƒ}ˆ jdkrF‡ fdd„| ¡ D ƒ}|S )Nc                   s*   i | ]"\}}|  ˆ j¡r| ˆ j¡|“qS r)   )rz   r•   Úremoveprefix©r{   ÚkÚv©r—   r)   r+   Ú
<dictcomp>i  s   þz4_ConfigurableModel._model_params.<locals>.<dictcomp>Úconfigurabler�   c                   s    i | ]\}}|ˆ j v r||“qS r)   )r“   r«   r®   r)   r+   r¯   o  s   )r   ÚgetÚitemsr“   )r—   r§   Úmodel_paramsr)   r®   r+   r¨   g  s    
þ

ÿz _ConfigurableModel._model_params)r§   r&   r'   c                   s²   t f i |pi ¤td|ƒ¤Ž}ˆ |¡‰ dd„ | ¡ D ƒ}‡ ‡fd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|d	�S )
z4Bind config to a Runnable, returning a new Runnable.r   c                 S  s   i | ]\}}|d kr||“qS )r°   r)   r«   r)   r)   r+   r¯   |  r   z2_ConfigurableModel.with_config.<locals>.<dictcomp>c                   s&   i | ]\}}|  ˆj¡ˆ vr||“qS r)   )rª   r•   r«   ©r³   r—   r)   r+   r¯   }  s   þr°   Úwith_configr)   r§   r�   )r   r   r¨   r²   r±   r’   r–   r›   r,   r‘   r�   r“   r•   )r—   r§   r&   Zremaining_configr�   r)   r´   r+   rµ   t  s,    
þ

ýÿ
ÿúz_ConfigurableModel.with_configr   )r'   c                 C  s*   ddl m}m} ttt||f tt f S )z%Get the input type for this runnable.r   )ÚChatPromptValueConcreteÚStringPromptValue)Zlangchain_core.prompt_valuesr¶   r·   r   r#   r’   r   )r—   r¶   r·   r)   r)   r+   Ú	InputType”  s    
þÿz_ConfigurableModel.InputTyper   )Úinputr§   r&   r'   c                 K  s   |   |¡j|fd|i|¤ŽS ©Nr§   )r¢   Úinvoke©r—   r¹   r§   r&   r)   r)   r+   r»   ¦  s    z_ConfigurableModel.invokec                 Ë  s"   |   |¡j|fd|i|¤ŽI d H S rº   )r¢   Úainvoker¼   r)   r)   r+   r½   ¯  s    z_ConfigurableModel.ainvokezOptional[Any]zIterator[Any]c                 k  s&   |   |¡j|fd|i|¤ŽE d H  d S rº   )r¢   Ústreamr¼   r)   r)   r+   r¾   ¸  s    z_ConfigurableModel.streamzAsyncIterator[Any]c                 K s6   |   |¡j|fd|i|¤Ž2 z3 d H W }|V  q6 d S rº   )r¢   Úastream©r—   r¹   r§   r&   Úxr)   r)   r+   r¿   Á  s    (z_ConfigurableModel.astreamF)Úreturn_exceptionszlist[LanguageModelInput]z5Optional[Union[RunnableConfig, list[RunnableConfig]]]Úboolz	list[Any])Úinputsr§   rÂ   r&   r'   c                  sp   |pd }|d u s&t |tƒs&t|ƒdkrVt |tƒr8|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__r)   r+   rÈ   Ë  s(    

ÿýüÿýüz_ConfigurableModel.batchc                ‹  s|   |pd }|d u s&t |tƒs&t|ƒdkr\t |tƒr8|d }|  |¡j|f||dœ|¤ŽI d H S tƒ j|f||dœ|¤ŽI d H S rÅ   )r�   rœ   rÇ   r’   r¢   ÚabatchrÉ   rÊ   rË   r)   r+   rÍ   ç  s(    

ÿýüÿýüz_ConfigurableModel.abatchzSequence[LanguageModelInput]z9Optional[Union[RunnableConfig, Sequence[RunnableConfig]]]z+Iterator[tuple[int, Union[Any, Exception]]]c                +  sˆ   |pd }|d u s&t |tƒs&t|ƒdkrdt |tƒr8|d }|  td|ƒ¡j|f||dœ|¤ŽE d H  n tƒ j|f||dœ|¤ŽE d H  d S ©Nr„   r   r   rÆ   )r�   rœ   rÇ   r’   r¢   r   Úbatch_as_completedrÉ   rÊ   rË   r)   r+   rÏ     s(    
ÿýü	ÿýüz%_ConfigurableModel.batch_as_completedzAsyncIterator[tuple[int, Any]]c                 s¨   |pd }|d u s&t |tƒs&t|ƒdkrtt |tƒr8|d }|  td|ƒ¡j|f||dœ|¤Ž2 z3 d H W }|V  q\6 n0tƒ j|f||dœ|¤Ž2 z3 d H W }|V  qŽ6 d S rÎ   )r�   rœ   rÇ   r’   r¢   r   Úabatch_as_completedrÉ   )r—   rÄ   r§   rÂ   r&   rÁ   rË   r)   r+   rÐ      s0    
ÿýûúÿýüz&_ConfigurableModel.abatch_as_completedzIterator[LanguageModelInput]c                 k  s&   |   |¡j|fd|i|¤ŽE d H  d S rº   )r¢   Ú	transformr¼   r)   r)   r+   rÑ   A  s    z_ConfigurableModel.transformz!AsyncIterator[LanguageModelInput]c                 K s6   |   |¡j|fd|i|¤Ž2 z3 d H W }|V  q6 d S rº   )r¢   Ú
atransformrÀ   r)   r)   r+   rÒ   J  s    (z_ConfigurableModel.atransformT)ÚdiffÚwith_streamed_output_listÚinclude_namesÚinclude_typesÚinclude_tagsÚexclude_namesÚexclude_typesÚexclude_tagszLiteral[True]zOptional[Sequence[str]]zAsyncIterator[RunLogPatch])r¹   r§   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r&   r'   c                K  s   d S r(   r)   ©r—   r¹   r§   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r&   r)   r)   r+   Úastream_logT  s    z_ConfigurableModel.astream_log)rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   zLiteral[False]zAsyncIterator[RunLog]c                K  s   d S r(   r)   rÛ   r)   r)   r+   rÜ   e  s    z8Union[AsyncIterator[RunLogPatch], AsyncIterator[RunLog]]c                K sF   |   |¡j|f|||||||
|	|dœ	|¤Ž2 z3 d H W }|V  q,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Á   r)   r)   r+   rÜ   v  s     
ÿöõZv2)ÚversionrÕ   rÖ   r×   rØ   rÙ   rÚ   zLiteral['v1', 'v2']zAsyncIterator[StreamEvent])r¹   r§   rÝ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r&   r'   c                K sD   |   |¡j|f||||||	||dœ|
¤Ž2 z3 d H W }|V  q*6 d S )N)r§   rÝ   rÕ   rÖ   r×   rÚ   rÙ   rØ   )r¢   Úastream_events)r—   r¹   r§   rÝ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r&   rÁ   r)   r)   r+   rÞ   •  s    
ÿ÷
öz!_ConfigurableModel.astream_eventszDSequence[Union[dict[str, Any], type[BaseModel], Callable, BaseTool]]z)Runnable[LanguageModelInput, BaseMessage])Útoolsr&   r'   c                 K  s   |   d¡|fi |¤ŽS )Nr�   ©r¦   )r—   rß   r&   r)   r)   r+   r�   ³  s    z_ConfigurableModel.bind_toolszUnion[dict, type[BaseModel]]z4Runnable[LanguageModelInput, Union[dict, BaseModel]])Úschemar&   r'   c                 K  s   |   d¡|fi |¤ŽS )NrŽ   rà   )r—   rá   r&   r)   r)   r+   rŽ   »  s    z)_ConfigurableModel.with_structured_output)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)Ú__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)   r)   rË   r+   r,   *  s¾   ú þ  ý ý ý ý ýû ýû ýû  ýû! ý ý	 ýô* ýô* ýô* ýõ()N)N)N)4Ú
__future__r   r2   Úcollections.abcr   r   r   Ú	importlibr   Útypingr   r   r	   r
   r   r   r   Zlangchain_core.language_modelsr   r   r   Z*langchain_core.language_models.chat_modelsr   r   Zlangchain_core.messagesr   r   Zlangchain_core.runnablesr   r   r   Zlangchain_core.runnables.schemar   Zlangchain_core.toolsr   Zlangchain_core.tracersr   r   Zpydanticr   Ztyping_extensionsr   r   Ú__all__r   r4   ru   r‚   rq   rr   r¡   r,   r)   r)   r)   r+   Ú<module>   sd   $
û
 ÿû
 ÿû ÿù  ý 	