� ���gHf���dZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z%ddl&Z&ddl'Z'ddl(m)Z)ddl*m+Z+dd l,m-Z.ej/e0��Z1Gd �d e2��Z3Gd �d e3��Z4Gd�de3��Z5Gd�de3��Z6Gd�de3��Z7Gd�de3��Z8Gd�de3��Z9Gd�de3��Z:Gd�de3��Z;Gd�de<��Z=Gd�de=��Z>d�d�d$�Z?d�d&�Z@d�d*�ZAd�d.�ZBd�d2�ZCejDd3�4��d�d8���ZEd�d:�ZFd�d;�ZGd�d=�ZHd�d@�ZId�dB�ZJd�dC�ZKd�dD�ZLejDd3�4��d�dF���ZMd�dI�ZNd�dL�ZOejDdM�4�� d�dNdO�d�dU���ZPejDd3�4��d�d�dW���ZQGdX�dYejR��ZSGdZ�d[ejR��ZTGd\�d]e+��ZUejV��ZWejXd�dc���ZYd�de�ZZejX d�d�dj���Z[ejX d�d�dl���Z\d�dm�Z]e dn��Z^ d�d�du�Z_d�dv�Z`d�dy�Zad�d|�Zbe)d}��ZcGd~�de��Zdd�d��Zed�d��Zfd�d��ZgejDd��4��d�d����Zhd�d�d��Zid�d��ZjdS)�zGeneric utility functions.�)� annotationsN)�Future�ThreadPoolExecutor)�Any�Callable�Dict� Generator�Iterable�Iterator�List�Literal�Mapping�Optional�Sequence�Tuple�TypeVar�Union�cast)�parse)� ParamSpec)�Retry)�schemasc��eZdZdZdS)�LangSmithErrorz=An error occurred while communicating with the LangSmith API.N��__name__� __module__� __qualname__�__doc__���_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/langsmith/utils.pyrr0s������G�G�G�Gr!rc��eZdZdZdS)�LangSmithAPIErrorz9Internal server error while communicating with LangSmith.Nrr r!r"r$r$4s������C�C�C�Cr!r$c��eZdZdZdS)�LangSmithRequestTimeoutz*Client took too long to send request body.Nrr r!r"r&r&8s������4�4�4�4r!r&c��eZdZdZdS)�LangSmithUserErrorzAUser error caused an exception when communicating with LangSmith.Nrr r!r"r(r(<s������K�K�K�Kr!r(c��eZdZdZdS)�LangSmithRateLimitErrorz7You have exceeded the rate limit for the LangSmith API.Nrr r!r"r*r*@s������A�A�A�Ar!r*c��eZdZdZdS)�LangSmithAuthErrorz-Couldn't authenticate with the LangSmith API.Nrr r!r"r,r,Ds������7�7�7�7r!r,c��eZdZdZdS)�LangSmithNotFoundErrorz%Couldn't find the requested resource.Nrr r!r"r.r.Hs������/�/�/�/r!r.c��eZdZdZdS)�LangSmithConflictErrorzThe resource already exists.Nrr r!r"r0r0L�������&�&�&�&r!r0c��eZdZdZdS)�LangSmithConnectionErrorz&Couldn't connect to the LangSmith API.Nrr r!r"r3r3P�������0�0�0�0r!r3c��eZdZdZdS)�LangSmithWarningzBase class for warnings.Nrr r!r"r6r6Ws������"�"�"�"r!r6c��eZdZdZdS)�LangSmithMissingAPIKeyWarningzWarning for missing API key.Nrr r!r"r8r8[r1r!r8�ctx�Optional[dict]�return�Union[bool, Literal['local']]c��ddlm}m}|p |��}|d�|dS|��rdStdtdd� ��� ��}|d kS) z"Return True if tracing is enabled.r)�get_current_run_tree�get_tracing_context�enabledNT� TRACING_V2�TRACING���default�true)�langsmith.run_helpersr>r?� get_env_var)r9r>r?�tc� var_results r"�tracing_is_enabledrK_s���O�O�O�O�O�O�O�O� � %�#�#�%�%�B�  �)�}� ��)�}��������t��\�;�y�RT�3U�3U�3U�V�V�V�J� �� �r!�boolc�,�tdd���dkS)z"Return True if testing is enabled.� TEST_TRACKINGrCrD�false�rHr r!r"�test_tracking_is_disabledrQrs�� ��� 3� 3� 3�w� >�>r!� arg_groups�Tuple[str, ...]rc���d�fd� }|S)z7Validate specified keyword args are mutually exclusive.�funcrr;c�L���tj���d��fd� ��}|S)N�argsr�kwargsr;c������fd��D��}d�t|��D��}|r3�fd�|D��}tdd�|��������|i���S)z3Validate exactly one arg in each group is not None.c�F��g|]}t�fd�|D������S)c3�F�K�|]}��|���dV��dS)N�)�get)�.0�argrXs �r"� <genexpr>zJxor_args.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>.<genexpr>s2�����J�J�#�f�j�j��o�o�.I�A�.I�.I�.I�.I�J�Jr!)�sum)r^� arg_grouprXs �r"� <listcomp>z@xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>~sF��������J�J�J�J��J�J�J�J�J���r!c�$�g|] \}}|dk� |��S�r\r )r^�i�counts r"rcz@xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>�s!��P�P�P�H�A�u�U�a�Z�Z�a�Z�Z�Zr!c�F��g|]}d��|����S)�, )�join)r^rfrRs �r"rcz@xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<listcomp>�s)���&X�&X�&X�A�t�y�y��A��'?�'?�&X�&X�&Xr!zFExactly one argument in each of the following groups must be defined: ri)� enumerate� ValueErrorrj)rWrX�counts�invalid_groups�invalid_group_namesrRrUs ` ��r"�wrapperz,xor_args.<locals>.decorator.<locals>.wrapper{s���������!+����F�Q�P� �&�0A�0A�P�P�P�N�� �&X�&X�&X�&X��&X�&X�&X�#� �9�� � �"5�6�6�9�9���� �4��(��(�(� (r!)rWrrXrr;r)� functools�wraps)rUrprRs` �r"� decoratorzxor_args.<locals>.decoratorzsC���� ��� � � )� )� )� )� )� )� � � )� �r!)rUrr;rr )rRrss` r"�xor_argsrtws)���������( �r!�response�(Union[requests.Response, httpx.Response]�Nonec�:� |���dS#tj$r-}tjt|��|j��|�d}~wt j$r9}t jt|���d|j��|j|���|�d}~wwxYw)z&Raise an error with the response text.Nz: )�requestru)�raise_for_status�requests� HTTPError�str�text�httpx�HTTPStatusErrorry)ru�es r"�raise_for_status_with_textr��s��� ��!�!�#�#�#�#�#�� � �?�?�?�� ��Q�����7�7�Q�>����� � �����#��1�v�v� (� (��� (� (��$�� � � ��  ��������s ��B�(A�B�!4B�B�enu�Union[enum.Enum, str]r}c�H�t|tj��r|jS|S)zGet the value of a string enum.)� isinstance�enum�Enum�value)r�s r"�get_enum_valuer��s#���#�t�y�!�!���y�� �Jr!r\)�maxsize�level�int�messagec�<�t�||��dS)z4Log a message at the specified level, but only once.N)�_LOGGER�log)r�r�s r"�log_oncer��s�� �K�K��w�����r!�Mapping[str, Any]c��|std���d|vrKd|vrtd|�d����|dd�dd�����Sd |vrtd |�d ����|d S) N�Message is empty.�lc�id�*Unexpected format for serialized message: z Message does not have an id.������MessagerC�type�&Unexpected format for stored message: z Message does not have a type.)rl�replace�lower�r�s r"�_get_message_typer��s��� �.��,�-�-�-� �w��� �w� � ��0�W�0�0�0��� ��t�}�R� �(�(��B�7�7�=�=�?�?�?� �� � ��1��1�1�1��� ��v��r!c��|std���d|vrd|vrtd|�d����|dSd|vrtd|�d����|dS) Nr�r�rXr�z Message does not have kwargs.�datar�z Message does not have data.)rlr�s r"�_get_message_fieldsr��s��� �.��,�-�-�-� �w��� �7� "� "��1�W�1�1�1��� ��x� � � �� � ��/��/�/�/��� ��v��r!�Dict[str, Any]c�H�t|��}t|��}||d�S)z&Extract message from a message object.�r�r�)r�r�)r�� message_type� message_datas r"�_convert_messager��s*��$�W�-�-�L�&�w�/�/�L� �,� 7� 7�7r!�inputs�List[Dict[str, Any]]c��d|vrd�|dD��Sd|vrt|d��gStd|�d����)aGExtract messages from the given inputs dictionary. Args: inputs (Mapping[str, Any]): The inputs dictionary. Returns: List[Dict[str, Any]]: A list of dictionaries representing the extracted messages. Raises: ValueError: If no message(s) are found in the inputs dictionary. �messagesc�,�g|]}t|����Sr )r�)r^r�s r"rcz,get_messages_from_inputs.<locals>.<listcomp>�s!��L�L�L�g� ��)�)�L�L�Lr!r�z-Could not find message(s) in run with inputs �.)r�rl)r�s r"�get_messages_from_inputsr��sc���V���L�L�� �9K�L�L�L�L��F��� �� �!2�3�3�4�4� �N�V�N�N�N� O� O�Or!�outputsc��d|vrtd|�d����|d}t|��dkr#tdt|���d|�d����|d}d|vrtd |�d ����t|d��S) a'Retrieve the message generation from the given outputs. Args: outputs (Mapping[str, Any]): The outputs dictionary. Returns: Dict[str, Any]: The message generation. Raises: ValueError: If no generations are found or if multiple generations are present. � generations�,No generations found in in run with output: r�r\z3Chat examples expect exactly one generation. Found z generations: rr�z"Unexpected format for generation: z%. Generation does not have a message.)rl�lenr��r�r��first_generations r"�#get_message_generation_from_outputsr��s����G�#�#��R��R�R�R�S�S�S��-�(�K� �;���1���� E��+�&�&� E� E�6A� E� E� E� � � �#�1�~���(�(�(�� 3�1A� 3� 3� 3� � � � �,�Y�7� 8� 8�8r!c��d|vr|dSd|vr6|d}t|��dkr|dStd|�d����td|�d����) z�Retrieve the prompt from the given inputs. Args: inputs (Mapping[str, Any]): The inputs dictionary. Returns: str: The prompt. Raises: ValueError: If the prompt is not found or if multiple prompts are present. �prompt�promptsr\rz$Multiple prompts in run with inputs z!. Please create example manually.z)Could not find prompt in run with inputs r�)r�rl)r�r�s r"�get_prompt_from_inputsr� s����6����h����F�����#�� �w�<�<�1� � ��1�:� �� /�6� /� /� /� � � � �J��J�J�J� K� K�Kr!c���d|vrtd|�d����|d}t|��dkrtd|�����|d}d|vrtd|�����|dS) z(Get the LLM generation from the outputs.r�r�r�r\zMultiple generations in run: rr~zNo text in generation: )rlr�r�s r"�get_llm_generation_from_outputsr�%s����G�#�#��R��R�R�R�S�S�S��-�(�K� �;���1����F��F�F�G�G�G�"�1�~�� �%�%�%��E�3C�E�E�F�F�F� �F� #�#r!� List[str]c�R� tjgd�tjtj���ddgS#tjtf$r] tjddgtjtj���dgcYS#tjtf$rt d���wxYwwxYw)z7Get the correct docker compose command for this system.)�docker�compose� --version)�stdout�stderrr�r�zdocker-composer�z�Neither 'docker compose' nor 'docker-compose' commands are available. Please install the Docker server following the instructions for your operating system at https://docs.docker.com/engine/install/)� subprocess� check_call�DEVNULL�CalledProcessError�FileNotFoundErrorrlr r!r"�get_docker_compose_commandr�2s������ .� .� .��%��%� � � � � �)�$�$�� � )�+<� =���� � � !�!�;�/�!�)�!�)� � � � � %�%� %� %� %���-�/@�A� � � ��E��� � �������s!�03�B&� /A<�9B&�<&B"�"B&�ls_schemas.BaseMessageLike�dictc��|jd|jid�}|jr*t|j��dkri|j�|dd<|S)z*Convert a LangChain message to an example.�contentr�rr��additional_kwargs)r�r�r�r�)r�� converteds r"�convert_langchain_messager�Ms`��� ��G�O�,�!�!�I� � �O�S��)B�%C�%C�a�%G�%G�1N�G�4M�1N� �&��-�.� �r!�obj�objectc ��ttt|dd��t��tt|dd��t��t |d��o"tt|d��t��g��S)z�Check if the given object is similar to BaseMessage. Args: obj (object): The object to check. Returns: bool: True if the object is similar to BaseMessage, False otherwise. r�Nr�r�)�allr��getattrr}r��hasattr)r�s r"�is_base_message_liker�Yst�� � �w�s�I�t�4�4�c� :� :� �w�s�$7��>�>�� E� E� �C�� � � J�Z���V�0D�0D�c�%J�%J� � � �r!�d)� LANGSMITH� LANGCHAIN)� namespaces�namerE� Optional[str]r�rc�x���fd�|D��}|D]'�tj����}|�|cS�(|S)a+Retrieve an environment variable from a list of namespaces. Args: name (str): The name of the environment variable. default (Optional[str], optional): The default value to return if the environment variable is not found. Defaults to None. namespaces (Tuple, optional): A tuple of namespaces to search for the environment variable. Defaults to ("LANGSMITH", "LANGCHAINs"). Returns: Optional[str]: The value of the environment variable if found, otherwise the default value. c���g|] }|�d����� S)�_r )r^� namespacer�s �r"rczget_env_var.<locals>.<listcomp>s'��� ?� ?� ?�y� � "� "�D� "� "� ?� ?� ?r!)�os�environr])r�rEr��namesr�s` r"rHrHksZ���( @� ?� ?� ?�J� ?� ?� ?�E������ ���t�$�$�� � ��L�L�L� � �Nr!Tc ��tj�dtdtd|rdnd��������S)z,Get the project name for a LangSmith tracer.�HOSTED_LANGSERVE_PROJECT_NAME�PROJECT�SESSIONrENrD)r�r�r]rH)�return_default_values r"�get_tracer_projectr��sY�� �:�>�>� (�� � ��0D�#N�9�9�$����  � � �  � �r!c�.��eZdZdZd d �fd� Zd d �Z�xZS)�FilterPoolFullWarningzFFilter urrllib3 warnings logged when the connection pool isn't reused.rCr�r}�hostr;rwc�X��t���|��||_dS)z�Initialize the FilterPoolFullWarning filter. Args: name (str, optional): The name of the filter. Defaults to "". host (str, optional): The host to filter. Defaults to "". N)�super�__init__�_host)�selfr�r�� __class__s �r"r�zFilterPoolFullWarning.__init__�s(��� ����������� � � r!rLc�H�|���}d|vrdS|j|vS)zJurllib3.connectionpool:Connection pool is full, discarding connection: ...z.Connection pool is full, discarding connectionT)� getMessager��r��record�msgs r"�filterzFilterPoolFullWarning.filter�s0�����!�!�� ;�3� F� F��4��z��$�$r!)rCrC)r�r}r�r}r;rw�r;rL)rrrrr�r�� __classcell__�r�s@r"r�r��s\�������P�P��������%�%�%�%�%�%�%�%r!r�c��eZdZdZdd�ZdS)�FilterLangSmithRetryz!Filter for retries from this lib.r;rLc�2�|���}d|vS)z!Filter retries from this library.�LangSmithRetry)r�r�s r"r�zFilterLangSmithRetry.filter�s �����!�!���s�*�*r!Nr�)rrrrr�r r!r"rr�s.������+�+�+�+�+�+�+�+r!rc��eZdZdZdS)rz&Wrapper to filter logs with this name.Nrr r!r"rr�r4r!r�logger�logging.Logger�filters�Sequence[logging.Filter]�Generator[None, None, None]c#�(K�t5|D]}|�|��� ddd��n #1swxYwY dV�t5|D]B} |�|���#t$rt�d��Y�?wxYw ddd��dS#1swxYwYdS#t5|D]B} |�|���#t$rt�d��Y�?wxYw ddd��w#1swxYwYwxYw)z�Temporarily adds specified filters to a logger. Parameters: - logger: The logger to which the filters will be added. - filters: A sequence of logging.Filter objects to be temporarily added to the logger. NzFailed to remove filter)� _FILTER_LOCK� addFilter� removeFilter� BaseExceptionr��warning)rrr�s r"� filter_logsr�s1���� �%�%�� %� %�F� � � �V� $� $� $� $� %�%�%�%�%�%�%�%�%�%�%�%����%�%�%�%�?� ���� � ?� ?�!� ?� ?��?��'�'��/�/�/�/��$�?�?�?��O�O�$=�>�>�>�>�>�?���� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?���� ?� ?� ?� ?� ?� ?��\� ?� ?�!� ?� ?��?��'�'��/�/�/�/��$�?�?�?��O�O�$=�>�>�>�>�>�?���� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?� ?���� ?� ?� ?� ?� ?���s��2�6�6�B*� B�A%�$B�%$B � B� B � B�B!�$B!�*D�2D�8C� D�$C5 �2D�4C5 �5D�9 D�D � D� D � D�cachec�,�|�|Stdd���S)z�Get the testing cache directory. Args: cache (Optional[str]): The cache path. Returns: Optional[str]: The cache path if provided, otherwise the value from the LANGSMITH_TEST_CACHE environment variable. N� TEST_CACHErDrP)rs r"� get_cache_dirr�s"�� ��� � �|�T� 2� 2� 2�2r!�path�Union[str, pathlib.Path]� ignore_hosts�Optional[Sequence[str]]c#���K� ddl}n#t$rtd���wxYwddlm}|���d�fd� }t j�|��\}}|�|� d ��s|� d ��rd nd |d gd�ddg|���}|� |��5dV�ddd��dS#1swxYwYdS)�Use a cache for requests.rNzNvcrpy is required to use caching. Install with:pip install -U "langsmith[vcr]")�_patchryrr;c�V����rt�fd��D����rdSi�_�S)Nc3�L�K�|]}�j�|��V��dS�N)�url� startswith)r^r�rys �r"r`z>with_cache.<locals>._filter_request_headers.<locals>.<genexpr>�s3�����V�V��� � 6� 6�t� <� <�V�V�V�V�V�Vr!)�any�headers)ryrs`�r"�_filter_request_headersz+with_cache.<locals>._filter_request_headers�sA���� � �C�V�V�V�V��V�V�V�V�V� ��4�����r!z.yamlz.yml�yaml�json� new_episodes)�uri�methodr�body� authorizationz Set-Cookie)� serializer�cassette_library_dir� record_mode�match_on�filter_headers�before_record_request)ryrr;r) �vcr� ImportError�langsmith._internalr� patch_urllib3r�r�split�VCR�endswith� use_cassette)rrr0r3r"� cache_dir� cache_file�ls_vcrs ` r"� with_cacher;�s������  �� � � � �� � � � �� .� � � � ���� <�;�;�;�;�;����!�!�!������� �G�M�M�$�/�/��I�z� �W�W��"�"�7�+�+� �/9�/B�/B�6�/J�/J� �F�F��&�#�2�2�2�'��6�5�� � �F� � � �Z� (� (��� ������������������������s� �$� C�C�"C�"Optional[Union[str, pathlib.Path]]c#�tK�|�/t||��5dV�ddd��dS#1swxYwYdSdV�dS)rN)r;)rrs r"�with_optional_cacher>s�����  �� ��l� +� +� � � �E�E�E� � � � � � � � � � � � ���� � � � � � � �����s �'�+�+c��tjtj���}d�|D��}d�|��S)Nc��g|]}d|v�|�� S)z langsmith/r )r^�lines r"rcz_format_exc.<locals>.<listcomp>%s"��L�L�L�t�<�t�3K�3K�d�3K�3K�3Kr!rC)� traceback�format_exception�sys�exc_inforj)�tb_lines�filtered_liness r"� _format_excrH"s:���)�3�<�>�>�:�H�L�L�x�L�L�L�N� �7�7�>� "� "�"r!�T��val�memo�Dict[int, Any]� max_depth�_depthc������t|��}t|dd��}|� |���S#t$rYnwxYw��kr|St|t��r"���fd�|���D��St|t ��r���fd�|D��St|t��rt���fd�|D����St|t��r���fd�|D��S|S)N� __deepcopy__c �h��i|].\}}t|���dz��t|���dz����/Sre�� _middle_copy)r^�k�vrOrNrLs ���r"� <dictcomp>z _middle_copy.<locals>.<dictcomp>:sZ��� � � ���1� ��D�)�V�a�Z� 8� 8�,��4��F�Q�J�;�;� � � r!c �:��g|]}t|���dz����SrerS�r^�itemrOrNrLs ���r"rcz _middle_copy.<locals>.<listcomp>A�+���P�P�P�D� �T�4��F�Q�J�?�?�P�P�Pr!c3�B�K�|]}t|���dz��V��dS)r\NrSrYs ���r"r`z_middle_copy.<locals>.<genexpr>Cs5�����U�U��\�$��i��!��D�D�U�U�U�U�U�Ur!c �:��h|]}t|���dz����SrerSrYs ���r"� <setcomp>z_middle_copy.<locals>.<setcomp>Er[r!) r�r�r r�r��items�list�tuple�set)rKrLrNrO�cls�copiers ``` r"rTrT,sg����� �s�)�)�C� �S�.�$� /� /�F� �� ��6�$�<�<� ��� � � � �D� ���� ����� ��#�t��� � � � � � � �� � � � �  � � � � �#�t���Q�P�P�P�P�P�P�C�P�P�P�P��#�u���V��U�U�U�U�U�U�QT�U�U�U�U�U�U��#�s���Q�P�P�P�P�P�P�C�P�P�P�P� �Js � 2� ?�?c���i} tj||��S#t$rB}t�dt |����t ||��cYd}~Sd}~wwxYw)z�Deep copy a value with a compromise for uncopyable objects. Args: val: The value to be deep copied. Returns: The deep copied value. zFailed to deepcopy input: %sN)�copy�deepcopyr r��debug�reprrT)rKrLr�s r"� deepish_copyrjJs{���D�'��}�S�$�'�'�'�� �'�'�'� � � �4�d�1�g�g�>�>�>��C��&�&�&�&�&�&�&�&����� '���s�� A%�7A �A%� A%�current_version�target_versionc�n�ddlm}|�|��}|�|��}||kS)zGCheck if the current version is greater or equal to the target version.r)�version)� packagingrnr)rkrlrn�current�targets r"�is_version_greater_or_equalrr_sA��!�!�!�!�!�!��m�m�O�,�,�G� �]�]�>� *� *�F� �f� �r!� identifier�Tuple[str, str, str]c���|rC|�d��dks*|�d��s|�d��rtd|�����|�dd��}|d}t |��dkr|dnd}d|vr4|�dd��\}}|r|std|�����|||fS|std|�����d||fS)aEParse a string in the format of owner/name:hash, name:hash, owner/name, or name. Args: identifier (str): The prompt identifier to parse. Returns: Tuple[str, str, str]: A tuple containing (owner, name, hash). Raises: ValueError: If the identifier doesn't match the expected formats. �/r\zInvalid identifier format: �:r�latest�-)rgrr6rlr4r�)rs�parts� owner_name�commit�ownerr�s r"�parse_prompt_identifierr~hs*�� �E� � � �C� � �1� $� $� � � �� %� %� %� � � �s� #� #� %��C�z�C�C�D�D�D� � � �S�!� $� $�E��q��J��U���a���U�1�X�X�X�F� �j��� �&�&�s�A�.�.� ��t�� I�D� I��G�:�G�G�H�H� H��d�F�"�"�� I��G�:�G�G�H�H� H��J��&�&r!�Pc�8��eZdZdZd�fd � Zd d d �d�fd�Z�xZS)�ContextThreadPoolExecutorz?ThreadPoolExecutor that copies the context to the child thread.rU�Callable[P, T]rW�P.argsrX�P.kwargsr;� Future[T]c ����t���ttdtft jtj��j |g|�Ri|������S)aCSubmit a function to the executor. Args: func (Callable[..., T]): The function to submit. *args (Any): The positional arguments to the function. **kwargs (Any): The keyword arguments to the function. Returns: Future[T]: The future for the function. .) r��submitrrrIrq�partial� contextvars� copy_context�run)r�rUrWrXr�s �r"r�z ContextThreadPoolExecutor.submit�ss��� �w�w�~�~� ���a�� ��!��,�.�.�2�D��;?����CI��� � � � � r!Nr\��timeout� chunksize�fn�Callable[..., T]� iterables� Iterable[Any]r��Optional[float]r�r�� Iterator[T]c�����d�tt|d����D���d ��fd� }t��j|g|�R||d��S) a�Return an iterator equivalent to stdlib map. Each function will receive its own copy of the context from the parent thread. Args: fn: A callable that will take as many arguments as there are passed iterables. timeout: The maximum number of seconds to wait. If None, then there is no limit on the wait time. chunksize: The size of the chunks the iterable will be broken into before being passed to a child process. This argument is only used by ProcessPoolExecutor; it is ignored by ThreadPoolExecutor. Returns: An iterator equivalent to: map(func, *iterables) but the calls may be evaluated out-of-order. Raises: TimeoutError: If the entire result iterator could not be generated before the given timeout. Exception: If fn(*args) raises for any values. c�4�g|]}tj����Sr )r�r�)r^r�s r"rcz1ContextThreadPoolExecutor.map.<locals>.<listcomp>�s!��Q�Q�Q�1�K�,�.�.�Q�Q�Qr!rrWrr;rIc�D������j�g|�R�Sr)�popr�)rW�contextsr�s ��r"� _wrapped_fnz2ContextThreadPoolExecutor.map.<locals>._wrapped_fn�s&���%�8�<�<�>�>�%�b�0�4�0�0�0� 0r!r�)rWrr;rI)�ranger�r��map)r�r�r�r�r�r�r�r�s ` @�r"r�zContextThreadPoolExecutor.map�s������<R�Q��c�)�A�,�>O�>O�8P�8P�Q�Q�Q�� 1� 1� 1� 1� 1� 1� 1��u�w�w�{� � � � � ���  � � � r!)rUr�rWr�rXr�r;r�) r�r�r�r�r�r�r�r�r;r�)rrrrr�r�r�r�s@r"r�r��ss�������I�I� � � � � � �:$(�� ( �( �( �( �( �( �( �( �( �( �( �( r!r��api_urlc�.�|p#tttdd�����}|���st d���|����d���d���d��S)zBGet the LangSmith API URL from the environment or the given value.�ENDPOINTzhttps://api.smith.langchain.comrDz!LangSmith API URL cannot be empty�"�'rv)rr}rH�stripr(�rstrip)r��_api_urls r"� get_api_urlr��s�����$� �� �5� � � ���H� �>�>� � �F� �!D�E�E�E� �>�>� � � !� !�#� &� &� ,� ,�S� 1� 1� 8� 8�� =� =�=r!�api_keyc���|�|ntdd���}|�|���sdS|����d���d��S)z8Get the API key from the environment or the given value.N�API_KEYrDr�r�)rHr�)r��api_key_s r"� get_api_keyr��sd��!�-�w�w�;�y�RV�3W�3W�3W�H���x�~�~�/�/���t� �>�>� � � !� !�#� &� &� ,� ,�S� 1� 1�1r!rc�� tj|��j�d��d}t j|��}|dkp)|�d��p|�d��S#tj$rYdSwxYw)z�Check if the URL is localhost. Parameters ---------- url : str The URL to check. Returns: ------- bool True if the URL is localhost, False otherwise. rwrz 127.0.0.1z0.0.0.0z::F)� urllib_parse�urlsplit�netlocr4�socket� gethostbynamer�gaierror)rr��ips r"� _is_localhostr��s�����&�s�+�+�2�8�8��=�=�a�@�� � !�&� )� )���[� �S�B�M�M�)�$<�$<�S�� � �d�@S�@S�S�� �?�����u�u����s�A5A8�8B � B ��web_urlc�T�|r|Stj|��}t|��rd}�n|t|j���d��rWt|j���dd��d}tj|�|�����}n�t|j���d��rWt|j���dd��d}tj|�|�����}n�t|j ��� d��rd}nVt|j ��� d ��rd }n,t|j ��� d ��rd }nd }|S)z1Get the host URL based on the web URL or API URL.zhttp://localhostz/apir\r)rz/api/v1zeu.zhttps://eu.smith.langchain.comzdev.zhttps://dev.smith.langchain.comzbeta.z https://beta.smith.langchain.comzhttps://smith.langchain.com) r��urlparser�r}rr6�rsplit� urlunparse�_replacer�r)r�r�� parsed_url�link�new_paths r"� get_host_urlr�s��������&�w�/�/�J��W���-�!��� �Z�_� � � &� &�v� .� .� -��z��'�'�.�.�v�q�9�9�!�<���&�z�':�':��':�'I�'I�J�J��� �Z�_� � � &� &�y� 1� 1� -��z��'�'�.�.�y�!�<�<�Q�?���&�z�':�':��':�'I�'I�J�J��� �Z� � � � *� *�5� 1� 1�-�/��� �Z� � � � *� *�6� 2� 2�-�0��� �Z� � � � *� *�7� 3� 3�-�1���,�� �Kr!r��depthc��|dkst|��st|��St|d��r|jSt |t j��rt|j|dz��St|d��rIt|d��r!t|j d��r |j jSt|j |dz��St|��S)Nr�rr\�__call__r�) �callabler}r�rr�rqr��_get_function_namerUr�r�)r�r�s r"r�r�s��� �q�y�y��� � �y��2�w�w���r�:�����{���"�i�'�(�(�6�!�"�'�5�1�9�5�5�5��r�:���:� �2�{� #� #� )��� �j�(I�(I� )��<�(� (�!�"�+�u�q�y�9�9�9� �r�7�7�Nr!rc��t|t��r|���dkp|dkSt|��S)z�Check if the value is truish. Args: val (Any): The value to check. Returns: bool: True if the value is truish, False otherwise. rF�1)r�r}r�rL)rKs r"� is_truishr�+s>���#�s���3��y�y�{�{�f�$�2��s� �2� ��9�9�r!r)r9r:r;r<r�)rRrSr;r)rurvr;rw)r�r�r;r})r�r�r�r}r;rw)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;rL)r�r}rEr�r�rr;r�)T)r;r�)rrrrr;r)rr�r;r�)rrrrr;r)rr<rrr;r)r;r})rJr) rKrIrLrMrNr�rOr�r;rI)rKrIr;rI)rkr}rlr}r;rL)rsr}r;rt)r�r�r;r})r�r�r;r�)rr}r;rL)r�r�r�r})r)r�rr�r�r;r})rKrr;rL)kr� __future__r� contextlibr�rfr�rq�loggingr��pathlibr�r�rD� threadingrB�concurrent.futuresrr�typingrrrr r r r r rrrrrrr�urllibrr�rr{�typing_extensionsr� urllib3.utilr� langsmithr� ls_schemas� getLoggerrr�� Exceptionrr$r&r(r*r,r.r0r3� UserWarningr6r8rKrQrtr�r�� lru_cacher�r�r�r�r�r�r�r�r�r�r�rHr��Filterr�rr�RLockr �contextmanagerrrr;r>rHrIrTrjrrr~rr�r�r�r�r�r�r�r r!r"�<module>r�sW�� � �"�"�"�"�"�"��������� � � � � � � � ��������� � � � ����� � � � ����� � � � ���������9�9�9�9�9�9�9�9�����������������������������������")�(�(�(�(�(� � � � �����'�'�'�'�'�'�������+�+�+�+�+�+� �'� �H� %� %��H�H�H�H�H�Y�H�H�H�D�D�D�D�D��D�D�D�5�5�5�5�5�n�5�5�5�L�L�L�L�L��L�L�L�B�B�B�B�B�n�B�B�B�8�8�8�8�8��8�8�8�0�0�0�0�0�^�0�0�0�'�'�'�'�'�^�'�'�'�1�1�1�1�1�~�1�1�1�#�#�#�#�#�{�#�#�#�'�'�'�'�'�$4�'�'�'� � � � � �&?�?�?�?� ����4 � � � � �������Q���� � � � �� � ����&����&8�8�8�8�P�P�P�P�(9�9�9�9�:L�L�L�L�2 $� $� $� $����Q������� ���4 � � � �����$���S�!�!�!�"��3� �����"�!��6���Q�������� ���&%�%�%�%�%�G�N�%�%�%�*+�+�+�+�+�7�>�+�+�+�1�1�1�1�1�U�1�1�1��y�� � � � ��?�?�?���?�2 3� 3� 3� 3� ��LP�'�'�'�'���'�T ��-1� � � � ��� �#�#�#�#� �G�C�L�L��EF������<'�'�'�'�*���� '� '� '� '�F�I�c�N�N��D �D �D �D �D � 2�D �D �D �N >� >� >� >�2�2�2�2�����*���Q������� ���0�����$ � � � � � r!
Memory